Different color bar chart from eCharts

后端 未结 3 677
粉色の甜心
粉色の甜心 2020-12-30 03:46

I was trying to create a different color bar. For Mon blue, Tue red, Wed green. Please help me how to write it. Line itemStyle: {normal: {color: \'blue\',\'red\', \'gr

3条回答
  •  离开以前
    2020-12-30 04:19

    My solution in June 2019 for needing different colors based on values: Create separate series for the different colors, and use a stacked chart. For example, I needed to create a graph with green bars for passing values and yellow bars for failing values. This was my implementation:

    var data = {};
    data.legendData = ['Sales','HR','Engineering'];
    data.greenSeriesData = ['-',96.38,98.43];
    data.yellowSeriesData = [44.23,'-','-'];
    
    var option = {
        title: {
            text: '2019 Progress',
            left: 'center'
        },
        xAxis: {
            type: 'category',
            data: data.legendData
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                formatter: function (val) {
                    return (val) + '%';
                }
            }
        },
        series: [{
            data: data.greenSeriesData,
            type: 'bar',
            stack: 'colorbyvalue',
            label: {
                show: true,
                position: 'insideTop',
                formatter: "{c}%",
                color: '#000000'
            },
            barWidth: 50,
            itemStyle: {
                color: 'green'
            }
        },
        {
            data: data.yellowSeriesData,
            type: 'bar',
            stack: 'colorbyvalue',
            label: {
                show: true,
                position: 'insideTop',
                formatter: "{c}%",
                color: '#000000'
            },
            barWidth: 50,
            itemStyle: {
                color: 'yellow'
            }
        }],
        animation: false
    };
    

提交回复
热议问题