Incubator-echarts: Positioning vertical legends dynamically left/right to a chart

Created on 7 Mar 2018  ·  2Comments  ·  Source: apache/incubator-echarts

echarts-vertical-legend

The problem:

As you can see in the image I've found no good way to position a vertical legend without hardcoding the width of the grid: { right: 200 }. This is not working well with very long and very short legends.

Expected behavior:

When you write legend: { orient: vertical, right: 10px } the legends really should not overlay the chart - it should automatically place itself beside it, with a default margin/padding. You should not have to defined a hardcoded pixel width for the grid to place the vertical legends beside it. Instead the legend section should dynamically adjust to the longest of the legends + padding.

Should work like this: https://www.highcharts.com/demo/line-basic

Most helpful comment

You will have the same problem if you have horizontal legend. I always use horizontal legend and with scroll type. This way the legend will not overlay the chart BUT you will not have all the legend options available at once.

Code:

legend: {
    type: 'scroll',
    orient: 'horizontal'
}

capturar

As you can see in the image, you will always have the same height for the legend and, at least form me, is easier to manipulate. Despite this, I think you are right. This is just the way I use the legend in order to avoid your problem.

All 2 comments

You will have the same problem if you have horizontal legend. I always use horizontal legend and with scroll type. This way the legend will not overlay the chart BUT you will not have all the legend options available at once.

Code:

legend: {
    type: 'scroll',
    orient: 'horizontal'
}

capturar

As you can see in the image, you will always have the same height for the legend and, at least form me, is easier to manipulate. Despite this, I think you are right. This is just the way I use the legend in order to avoid your problem.

You will have the same problem if you have horizontal legend. I always use horizontal legend and with scroll type. This way the legend will not overlay the chart BUT you will not have all the legend options available at once.

Code:

legend: {
    type: 'scroll',
    orient: 'horizontal'
}

capturar

As you can see in the image, you will always have the same height for the legend and, at least form me, is easier to manipulate. Despite this, I think you are right. This is just the way I use the legend in order to avoid your problem.

Thanks, now my graph looks much better.

Was this page helpful?
0 / 5 - 0 ratings