echarts icon indicating copy to clipboard operation
echarts copied to clipboard

Suggestion: Scaling the chart down when there is overlap with the legend

Open jeffrey-roosendaal opened this issue 10 years ago • 14 comments

I used to work with Highcharts, but switched to ECharts. And even with Chinese documentation, it's way easier to use, so nice job!

Though there is one function I miss in ECharts, and that is setting the legend to not overlap the chart, by automatically scaling the chart down when there is overlap.

I've created a jsfiddle to illustrate what I mean: http://jsfiddle.net/gw7gwyqv/2/

See what happens when you resize the chart window? The chart gets larger/smaller to prevent overlapping with the legend. This is a really nice feature I think.

I don't know if this will be easy to implement (probably not...), but maybe you can add something like: options.legend.overlap: (boolean)


Also, the legend overlaps with the toolbox too, which should not happen in any case, right?

legend-overlap

jeffrey-roosendaal avatar Apr 15 '16 09:04 jeffrey-roosendaal

Hi Jeffery, glad to hear you like echarts and can work with it easily. We will have English doc soon.

About the overlapping problem, we knew it's really annoying. And we have discussed if there is a way to get the layout done automatically to avoid overlap. Not only between the chart and legend, but also many other components like toolbox. But sadly we haven't found a elegant way to achieve that.

And I think the chart is the most important in the view so it is not a good way to avoid overlapping by scaling the chart. Maybe it's better to render the legend outside with html and let css do the complicate layout job. Like the following code

option: {
    legend: {
        // Not show the legend, instead rendering it with html
        show: false,
        data: ['Quatro', 'Esmee'],
        selected: {
            'Quatro': true,
            'Esmee': true
        }
    }
};

$el1.click(function () {
    chart.setOption({
        legend: {
            selected: {
                Quatro: false
            }
        }
    });
})

pissang avatar Apr 15 '16 10:04 pissang

Thanks for the suggestion. I've not thought about that.

I see, you're right about it being not the best option. But sometimes it's just not worth creating a custom legend (lot of extra work), and then you may rather just see a shrinked chart.

But, I'm going to use your suggestion, I think that will be the best option, and it solves my problem. Thanks again for the help!

jeffrey-roosendaal avatar Apr 15 '16 10:04 jeffrey-roosendaal

Yes, agree with that it has a lot of work that developer should not concern. Maybe we can provide a legend extension which is rendered with HTML and CSS instead of canvas

pissang avatar Apr 16 '16 07:04 pissang

大概的意思就是不显示下面的legend,然后点击一下一个数据块,就隐藏这个数据块,那如果我再想让这个数据块显示回来,不就不行了吗?

lixiaojian avatar Apr 28 '16 06:04 lixiaojian

hi there ~, the same to you about the question, I have a little feature added in 【src/coord/cartesian/Grid.js】to deal this . just like:

        // Minus label size
        if (gridModel.get('containLabel')) {
            var legendVisibleHeight = 0;
            each(axesList, function(axis) {

                //add Start @mickle.zy 2016-05-04 17:19:34
                if (gridModel.get('containLegend')) {
                    legendVisibleHeight = adjustByLegendHeight() || 0;
                    gridRect.y += legendVisibleHeight;
                    gridRect.height = gridRect.height - legendVisibleHeight;
                }
                //add End @mickle.zy 2016-05-04 17:19:34


zhaoyangsoft avatar May 04 '16 09:05 zhaoyangsoft

有没有办法知道lengend占几行或何时换行,若知道legend有多少行就可以大概计算出Grid的位置了。

Hongmei225 avatar May 19 '16 15:05 Hongmei225

Hi, may I know if you have done any enhancements to solve the overlapping issue, please?

ljseb avatar Apr 03 '17 00:04 ljseb

Any news?

mxswat avatar Jun 07 '17 20:06 mxswat

Any updated on this?

sajal50 avatar Jul 24 '17 23:07 sajal50

Latest version support scrollable legend. Which may solve this overlapping issue. See https://ecomfe.github.io/echarts-doc/public/en/option.html#legend.type

pissang avatar Sep 14 '17 08:09 pissang

Interesting, I believe that having a custom legend component would be extra effort and complicated(specially if you would like to keep the series on/off functionality). In the other hand I understand also the Canvas rendering limitations. I will try combining to have more space and try on the scrollable suggestion. Either way I wanted to express that doing as original request would be awesome.

EvaristoPerez avatar Jul 08 '21 20:07 EvaristoPerez

I would suggest to customize legend by html. It's much easy than canvas.

susiwen8 avatar Jul 09 '21 01:07 susiwen8

I work in angualar and I solved it by separating the chart into 2 component, one is a component where I draw the legend by myself and one is to draw pie only using echarts. both are contained under a parent component having display: flex where I have flex-grow: 1 for the pie child component. this solved the responseness issue for me.

zohar1000 avatar Aug 09 '21 14:08 zohar1000

I work in angualar and I solved it by separating the chart into 2 component, one is a component where I draw the legend by myself and one is to draw pie only using echarts. both are contained under a parent component having display: flex where I have flex-grow: 1 for the pie child component. this solved the responseness issue for me.

How did you do that ? And do you maybe know a way to create a sub-legend too? Like you have a legend with categories and some categories have sub-categories, so you create a legend and a sublegend which is only shown when you click over the category which contains sub-categories? Would be really helpful.

gentritg avatar Oct 20 '21 14:10 gentritg