echarts 柱状图根据值的大小显示不同的颜色

echarts yekong 594℃

当值大于65显示粉色当值小于65显示深红色
wanjunshijie 2021-03-25 at 15.41.09

var data = {
                tooltip: {
                    trigger: 'axis',
                    axisPointer: { // 坐标轴指示器,坐标轴触发有效
                        type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
                    },
                    formatter: '{c}'
                },
                notMerge: true,
                grid: {
                    left: '5%',
                    right: '8%',
                    bottom: '1%',
                    top: '8%',
                    containLabel: true
                },
                xAxis: [{
                    type: 'category',
                    data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13'],
                    axisTick: { //轴刻度线
                        show: false
                    },

                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: 'rgba(163, 134, 123, 1)'
                        }
                    },
                    axisLine: {
                        show: false,
                        textStyle: {
                            color: 'rgba(179, 157, 162, 1)'
                        }
                    },
                }],
                yAxis: [{
                    type: 'value',
                    axisTick: {
                        show: false
                    },
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: 'rgba(163, 134, 123, 1)'
                        }
                    },
                    axisLine: {
                        show: false
                    },
                }],
                series: [{
                    name: '历史数据曲线',
                    type: 'bar',
                    data: [],
                    barWidth: 5,
                    itemStyle: {
                        normal: {
                            label: {
                                show: false,
                                formatter: function(v) {
                                    return that.dataIndex == v.dataIndex ? v.value : '';
                                },
                                position: 'top',
                                distance: 0,
                                color: '#434e79',
                                fontSize: 14,
                                backgroundColor: {
                                    image: icon,
                                },
                                padding: [0, 5, 5, 5],
                                borderRadius: 50
                            }
                        }
                    },
                    markLine: {
                        symbol: "none",
                        data: [{
                            silent: false,
                            lineStyle: {
                                type: "solid",
                                color: "rgba(174, 87, 108, 1)"
                            },
                            yAxis: "65"
                        }]
                    },
                }]
            };
            var data1 = [];
            var data2 = [40, 45, 55, 70, 75, 50, 60, 60, 75, 65, 60, 60, 60]
            for (var i = 0; i < data2.length; i++) {
                if (data2[i] < 65) {
                    data1.push({
                        value: data2[i],
                        itemStyle: {
                            normal: {
                                barBorderRadius: [5, 5, 0, 0],
                                color: 'rgba(158, 69, 89, 1)'
                            }
                        }
                    })
                } else {
                    data1.push({
                        value: data2[i],
                        itemStyle: {
                            normal: {
                                barBorderRadius: [5, 5, 0, 0],
                                color: 'rgba(239, 50, 108, 1)'
                            }
                        }
                    })
                }
            }
            data.series[0].data = data1;
            this.option2 = data;
喜欢 (0)