Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am using ECharts to show the trend data in line chart. I have 50 series to show in the line chart. Every series has a legend to show. I want to show the legends on top of the chart. But, I want to show the legends in maximum 3 lines. And if legends doesn't fit in the 3 lines then I want to show the vertical scroll. But, I am not able to show the vertical scroll with maximum of 3 lines of legends. Every line should show more than one legend in it.

option = {

    tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b} : {c}'
    },
    legend: [{
        left: 'left',width:'50%',
        type:'scroll',
        orient:'vertical',
        height:'100',
        selectedMode:'multiple',
        //pageButtonPosition:'end',
        //formatter:'legend {name} ',
        data: ['saaaaaaaaaaaaaaa0', 'saaaaaaaaaaaaaaa1','saaaaaaaaaaaaaaa2','saaaaaaaaaaaaaaa3'
        ,'saaaaaaaaaaaaaaa4','saaaaaaaaaaaaaaa8'
        , 'saaaaaaaaaaaaaaa9','saaaaaaaaaa10','saaaaaaaaaa13','saaaaaaaaaa14','saaaaaaaaaa11'
        , 'saaaaaaaaaa12','saaaaaaaaaa15','saaaaaaaaaa16'
        ,'saaaaaaaaaa17'],

    },
    {
        left: 'right',width:'50%',height:'auto',
        data: ['saaaaaaaaaaaaaaa5','saaaaaaaaaaaaaaa6','saaaaaaaaaaaaaaa7'],

    }
    ],
    xAxis: {
        type: 'category',
        name: 'x',
        splitLine: {show: false},
        data: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']
    },
    grid: {
       height:'auto'

    },
    yAxis: {
        type: 'log',
        name: 'y'
    },
    series: [
        {
            name: 'saaaaaaaaaaaaaaa0',
            type: 'line',
            data: [1, 3, 9, 27, 81, 247, 741, 2223, 6669]
        },
        {
            name: 'saaaaaaaaaaaaaaa1',
            type: 'line',
            data: [1, 2, 4, 8, 16, 32, 64, 128, 256]
        },
        {
            name: 'saaaaaaaaaaaaaaa2',
            type: 'line',
            data: [1/2, 1/4, 1/8, 1/16, 1/32, 1/64, 1/128, 1/256, 1/512]
        },
          {
            name: 'saaaaaaaaaaaaaaa3',
            type: 'line',
            data: [1, 3, 9, 27, 81, 247, 741, 2223, 6669]
        },
        {
            name: 'saaaaaaaaaaaaaaa4',
            type: 'line',
            data: [1, 2, 4, 8, 16, 32, 64, 128, 256]
        },
        {
            name: 'saaaaaaaaaaaaaaa5',
            type: 'line',
            data: [1/2, 1/4, 1/8, 1/16, 1/32, 1/64, 1/128, 1/256, 1/512]
        },
          {
            name: 'saaaaaaaaaaaaaaa6',
            type: 'line',
            data: [1, 2, 4, 8, 16, 32, 64, 128, 256]
        },
        {
            name: 'saaaaaaaaaaaaaaa7',
            type: 'line',
            data: [1/2, 1/4, 1/8, 1/16, 1/32, 1/64, 1/128, 1/256, 1/512]
        },
              {
            name: 'saaaaaaaaaaaaaaa8',
            type: 'line',
            data: [1, 3, 9, 27, 81, 247, 741, 2223, 6669]
        },
        {
            name: 'saaaaaaaaaaaaaaa9',
            type: 'line',
            data: [1, 2, 4, 8, 16, 32, 64, 128, 256]
        },
        {
            name: 'saaaaaaaaaa10',
            type: 'line',
            data: [1/2, 1/4, 1/8, 1/16, 1/32, 1/64, 1/128, 1/256, 1/512]
        },
          {
            name: 'saaaaaaaaaa11',
            type: 'line',
            data: [1, 3, 9, 27, 81, 247, 741, 2223, 6669]
        },
        {
            name: 'saaaaaaaaaa12',
            type: 'line',
            data: [1, 2, 4, 8, 16, 32, 64, 128, 256]
        },
        {
            name: 'saaaaaaaaaa13',
            type: 'line',
            data: [1/2, 1/4, 1/8, 1/16, 1/32, 1/64, 1/128, 1/256, 1/512]
        },
          {
            name: 'saaaaaaaaaa14',
            type: 'line',
            data: [1, 2, 4, 8, 16, 32, 64, 128, 256]
        },
        {
            name: 'saaaaaaaaaa15',
            type: 'line',
            data: [1/2, 1/4, 1/8, 1/16, 1/32, 1/64, 1/128, 1/256, 1/512]
        }
    ]
};


What I have tried:

Quote:
I tried with vertical and horizontal scroll. In vertical scroll, it shows only one legend in one line. this is the problem. Actually, ECharts should show the what ever possible legends in one line. If there is enough space to have 2 legends in one line, it should show 2 legends in one line. It should show 3 lines and if all legends doesn't fit in three lines, then should add vertical scroll. But, currently legends overlap to chart.
Posted
Updated 26-Jul-19 9:58am

1 solution

height:'100',


Seems sort of low for "3 items". Try 200 or 300.
 
Share this answer
 
Comments
Ashokyede 30-Jul-19 3:35am    
this is not the solution. If you have tried it, then you can see that legend shows only one item in one line where I need to show you can say 3 items in a line.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900