var data1 = [ 2.0, 5.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3 ] var data2 = [ 2.0, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3 ] option = { tooltip: { trigger: 'axis', axisPointer: { type: 'cross', crossStyle: { color: '#999' } } }, legend: { data: ['Evaporation', 'Precipitation', 'Temperature'] }, xAxis: [ { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], axisPointer: { type: 'shadow' } } ], yAxis: [ { type: 'value', name: 'Precipitation', min: 0, max: 250, interval: 50, axisLabel: { formatter: '{value} ml' } }, ], series: [ { name: 'Evaporation', type: 'bar', itemStyle: { //通常情况下: normal: { // 每个柱子的颜色即为colorList数组里的每一项,如果柱子数目多于colorList的长度,则柱子颜色循环使用该数组 color: function (params) { console.log(params) if (data1[params.dataIndex] < data2[params.dataIndex]) { return "red"; } else { return 'green' } } }, }, tooltip: { valueFormatter: function (value) { return value + ' ml'; } }, data: data1 }, { name: 'Precipitation', type: 'bar', tooltip: { valueFormatter: function (value) { return value + ' ml'; } }, itemStyle: { //通常情况下: normal: { // 每个柱子的颜色即为colorList数组里的每一项,如果柱子数目多于colorList的长度,则柱子颜色循环使用该数组 color: function (params) { console.log(params) if (data2[params.dataIndex] < data1[params.dataIndex]) { return "red"; } else { return 'green' } } }, }, data: data2 } ] };