Suggestion: Scaling the chart down when there is overlap with the legend
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?
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
}
}
});
})
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!
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
大概的意思就是不显示下面的legend,然后点击一下一个数据块,就隐藏这个数据块,那如果我再想让这个数据块显示回来,不就不行了吗?
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
有没有办法知道lengend占几行或何时换行,若知道legend有多少行就可以大概计算出Grid的位置了。
Hi, may I know if you have done any enhancements to solve the overlapping issue, please?
Any news?
Any updated on this?
Latest version support scrollable legend. Which may solve this overlapping issue. See https://ecomfe.github.io/echarts-doc/public/en/option.html#legend.type
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.
I would suggest to customize legend by html. It's much easy than canvas.
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.
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.