多legend多y柱状图

by vpt940417

HTML

<script src="https://cdn.bootcss.com/echarts/3.7.1/echarts.min.js"></script>
<div id="chart" ref="chart1" style="height: 400px"></div>

CSS

body{
  background-color: #133155;
}

JavaScript

// 基于准备好的dom,初始化echarts实例
    var myChart = echarts.init(document.getElementById('chart'));

    // 指定图表的配置项和数据
    var chartData = {
      data: [
        ["全部", 4.7, 16.1, 3.2],
        ["国产", 2.6, 10.1, 1.4],
        ["进口", 2.1, 6, 1.8]
      ],
      legend: ["销量", "销售收入", "单箱均价"]
    };
    var itemStyles = [{
      normal: {
        show: true,
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          offset: 1,
          color: '#0A5CFE'
        }, {
          offset: 0,
          color: '#1BD6FF'
        }, ]),
        barBorderRadius: [50, 50, 0, 0],
      }
    }, {
      normal: {
        show: true,
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          offset: 1,
          color: '#A34E63'
        }, {
          offset: 0,
          color: '#E4909E'
        }, ]),
        barBorderRadius: [50, 50, 0, 0],
      }
    }, {
      normal: {
        show: true,
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          offset: 1,
          color: '#5656A3'
        }, {
          offset: 0,
          color: '#938EE9'
        }, ]),
        barBorderRadius: [50, 50, 0, 0],
      }
    }];
    var option = {
      grid: {
        top: '50',
        left: '2',
        right: '20',
        bottom: '20',
        containLabel: true
      },
      legend: {
        show: true,
        padding: [0, 40, 0, 0],
        left: 'right',
        data: [{
          name: this.chartData.legend[0],
          icon: 'circle',
          textStyle: {
            color: '#fff'
          }
        }, {
          name: this.chartData.legend[1],
          icon: 'circle',
          textStyle: {
            color: '#fff'
          }
        }, {
          name: this.chartData.legend[2],
          icon: 'circle',
          textStyle: {
            color: '#fff'
          }
        }]
      },
      color: ['#FFC001'],
      xAxis: {
        type: 'category',
        data: this.xLineData(),
        axisLine: {
          lineStyle:...