echarts柱形图 每个柱子设置不同的渐变色

 实现如图所示效果

option配置项如下

  let options = {
                grid: {
                    show: false,
                    left: '20',
                    top: 20,
                    right: '20',
                    bottom: '0',
                    containLabel: true
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        label: {
                            backgroundColor: '#6a7985'
                        }
                    }
                },
                legend: {
                    show: false,
                    bottom: 0,
                    textStyle: {
                        color: 'rgba(255, 255, 255, 0.65)'
                    }
                },
                xAxis: [
                    {
                        type: 'category',
                        axisTick: { show: false },

                        axisLabel: {
                            show: true,
                            interval: 0,
                            textStyle: {
                                color: 'rgba(255,255,255,0.65)', // 更改坐标轴文字颜色
                                fontSize: 12 // 更改坐标轴文字大小
                            }
                        },
                        axisLine: {
                            show: true,
                            lineStyle: {
                                color: "rgba(255,255,255,0.2)",
                                width: 1,
                                type: "solid"
                            },
                        },
                        data: this.chartData.xAxis
                    }
                ],
                yAxis: [

                    {
                        type: 'value',
                        nameTextStyle: {
                            color: 'rgba(255, 255, 255, 0.45)'
                        },
                        axisLabel: {
                            show: true,
                            textStyle: {
                                color: 'rgba(255,255,255,0.65)', // 更改坐标轴文字颜色
                                fontSize: 12 // 更改坐标轴文字大小
                            }
                        },
                        splitLine: {
                            show: true,
                            lineStyle: {
                                color: 'rgba(255, 255, 255, 0.1)'
                            }

                        },
                        axisTick: { show: false },
                        axisLine: {
                            show: false,

                        },
                    }
                ],
                series: [
                    {
                        type: 'bar',
                        barWidth: 20,
                        itemStyle: {
                            normal: {
                                //柱体的颜色
                                //右,下,左,上(1,0,0,0)表示从正右开始向左渐变
                                color: function (params) {
                                    console.log(params);
                                    var colorList = [
                                        ['#00D273FF', '#00D27300'],
                                        ['#1AAF87FF', '#1AAF8700'],
                                        ['#00B1FFFF', '#00B1FF00'],
                                        ['#FFA900FF', '#FFA90000']
                                    ];

                                    var colorItem = colorList[params.dataIndex];
                                    return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                        offset: 0,
                                        color: colorItem[0]
                                    },
                                    {
                                        offset: 1,
                                        color: colorItem[1]
                                    }
                                    ], false);
                                },
                            },
                        },
                        data: this.chartData.series
                    }
                ]
            };

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阁下何不同风起?

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值