chartsbar-chartlinechartecharts

Adjust position of a line chart series symbol using echarts


I have created chart in E-Chart.It has two vertical bars with two lines above them. I need to place the symbols at the intersection of bars and lines . It should be like first chart in the picture

But in my chart the symbol position is placed on the xaxis value.please refer the second chart. Is there any possible way to change the position of symbols.

Image link:

enter image description here


Solution

  • You can get the bars and line symbols to align by interspersing nulls or blank values in each of your data series. Here's a sample option:

    option = {
        xAxis: [
            {
                // true axis for all bar and line series
                type: 'category',
                show: false,
                data: [1,1,2,2,3,3,4,4,5,5]
            },
            {
                // axis used for display; not associated with any series
                type: 'category',
                show: true,
                position: 'bottom',
                data: [1,2,3,4,5]
            }
        ],
        yAxis: {
            type: 'value'
        },
        series: [{
            type: 'bar',
            // xAxisIndex associates the series with the first (real) x-axis; may not be strictly necessary, but included for clarity
            xAxisIndex: 0,
            itemStyle: {
                barBorderRadius: 12
            },
            color: '#1ab7c8',
            // barGap is used to center the bar over the x-axis value, in line with the line symbol
            barGap: '-100%',
            barWidth: 32,
            data: [50, '-', 40, '-', 55, '-', 65, '-', 50]
        },
    {
            type: 'bar',
            xAxisIndex: 0,
            itemStyle: {
                barBorderRadius: 12
            },
            color: '#fa6176',
            barWidth: 32,
            data: ['-', 50, '-', 40, '-', 64, '-', 25, '-', 50]
        },
        {
            type: 'line',
            xAxisIndex: 0,
            color: '#1ab7c8',
            symbolSize: 16,
            // connectNulls is used to connect lines across the blank values
            connectNulls: true,
            data: [53, '-', 52, '-', 79, '-', 68, '-', 79]
        },
        {
            type: 'line',
            xAxisIndex: 0,
            color: '#fa6176',
            symbolSize: 16,
            connectNulls: true,
            data: ['-', 53, '-', 55, '-', 75, '-', 90, '-', 75]
        }
        ]
    };
    

    Here's an image of the rendered chart.

    enter image description here

    Here are links to docs on some of the relevant echarts chart configuration options: