echarts柱状图颜色渐变样式

 option: {
        title: {
          text: ''
        },
        color: [
          {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              { offset: 0, color: '#00DCFB' }, // 设置颜色渐变
              { offset: 1, color: '#14566B' }
            ]
          },
          {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              { offset: 0, color: '#FF515A' },
              { offset: 1, color: '#FFDD53' }
            ]
          },
          {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              { offset: 0, color: '#6574E2' },
              { offset: 1, color: '#261164' }
            ]
          }
        ],
        tooltip: {
          trigger: 'axis'
        },
        // 想要显示图例,要和series里name想对应
        legend: {
          data: ['委托', '样品', '任务'],
          textStyle: {
            color: '#fff',
            fontSize: 20
          },
          right: 10,
          icon: 'circle'
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          axisTick: { show: false },
          data: [],
          axisLabel: {
            show: true,
            textStyle: {
              color: 'rgb(167,169,173)', // 更改坐标轴文字颜色
              fontSize: 20 // 更改坐标轴文字大小
            }
          }
        },
        yAxis: {
          type: 'value',
          name: '单位 (个)',
          // 坐标轴图例文字
          nameTextStyle: {
            color: '#fff',
            fontSize: 20
          },
          min: 0,
          axisLabel: {
            show: true,
            textStyle: {
              color: 'rgb(167,169,173)', // 更改坐标轴文字颜色
              fontSize: 20 // 更改坐标轴文字大小
            }
          }
        },
        series: [
          { name: '委托', type: 'bar', data: [] },
          { name: '样品', type: 'bar', data: [] },
          { name: '任务', type: 'bar', data: [] }
        ]
      }

单个柱状图颜色修改

 series: [
          {
            name: '数量',
            type: 'bar',
            data: [],
            itemStyle: {
              normal: {
                // 每根柱子颜色设置
                color: function(params) {
                  const colorList = [
                    '#c23531',
                    '#2f4554',
                    '#61a0a8',
                    '#d48265',
                    '#91c7ae',
                    '#749f83',
                    '#ca8622',
                    '#bda29a',
                    '#6e7074',
                    '#546570',
                    '#c4ccd3',
                    '#4BABDE',
                    '#FFDE76',
                    '#E43C59',
                    '#37A2DA'
                  ]
                  return colorList[params.dataIndex]
                }
              }
            }
          }
        ]

 

 单个柱状图渐变颜色修改

import echarts from 'echarts'

series: [
          {
            name: '数量',
            type: 'bar',
            data: [],
            itemStyle: {
              normal: {
                // 每根柱子颜色设置
                color: function(params) {
                  const colorList = [
                    new echarts.graphic.LinearGradient(
                      0,
                      1,
                      0,
                      0,
                      [
                        { offset: 0, color: '#00DCFB' },
                        { offset: 1, color: '#14566B' }
                      ],
                      false
                    ),
                    // 2
                    new echarts.graphic.LinearGradient(
                      0,
                      1,
                      0,
                      0,
                      [
                        { offset: 0, color: '#FF515A' },
                        { offset: 1, color: '#FFDD53' }
                      ],
                      false
                    ),
                    // 3
                    new echarts.graphic.LinearGradient(
                      0,
                      1,
                      0,
                      0,
                      [
                        { offset: 0, color: '#6574E2' },
                        { offset: 1, color: '#261164' }
                      ],
                      false
                    ),
                    // 4
                    new echarts.graphic.LinearGradient(
                      0,
                      1,
                      0,
                      0,
                      [
                        { offset: 0, color: '#FCBC00' },
                        { offset: 1, color: '#B17B00' }
                      ],
                      false
                    ),
                    // 5
                    new echarts.graphic.LinearGradient(
                      0,
                      1,
                      0,
                      0,
                      [
                        { offset: 0, color: '#33BDAB' },
                        { offset: 1, color: '#005154' }
                      ],
                      false
                    )
                  ]
                  return colorList[params.dataIndex]
                }
              }
            }
          }
        ]

  • 8
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值