Skip to content Skip to sidebar Skip to footer

Multiple Color For A Bar(yaxis) Using Echart

I want to make a bar-chart like this using ECHARTS : I have tried using their example, but I don't find any option to make it multiple colors. I got an answer here, it is not usef

Solution 1:

You want to have different colors for each series in the stacked bar? Just draw imaginary vertical line across all series value and set color style for all crossing values.


{
          name: 'Series-1',
          type: 'bar',
          stack: '1',
          data: [5, { value: 20, itemStyle: { color: 'blue'} }, 36, 10, 10, 20]
      },{
          name: 'Series-2',
          type: 'bar',
          stack: '1',
          data: [5, {value: 20, itemStyle: { color: 'green'} }, 36, 10, 10, 20]
      }

var myChart = echarts.init(document.getElementById('main'));
  var option = {
      title: {
          text: 'ECharts'
      },
      tooltip: {},
      legend: {
          data:['Label']
      },
      xAxis: {
          data: ["Category1","Category2","Category3","Category4","Category5","Category6"]
      },
      yAxis: {},
      series: [{
          name: 'Series-1',
          type: 'bar',
          stack: '1',
          data: [5, { value: 20, itemStyle: { color: 'blue'} }, 36, 10, 10, 20]
      },{
          name: 'Series-2',
          type: 'bar',
          stack: '1',
          data: [5, {value: 20, itemStyle: { color: 'green'} }, 36, 10, 10, 20]
      }
      ]
  };

  myChart.setOption(option);
<scriptsrc="https://cdn.jsdelivr.net/npm/echarts@4.7.0/dist/echarts.min.js"></script><divid="main"style="width: 600px;height:400px;"></div>

Post a Comment for "Multiple Color For A Bar(yaxis) Using Echart"