echart 漸變色找不到 $echarts 怎么實(shí)現(xiàn)

有時(shí)候有一些稀奇古怪項(xiàng)目用了稀奇古怪的自研UI 二次封裝echarts 導(dǎo)致行內(nèi) new echarts 報(bào)錯(cuò)
設(shè)置漸變色可以這樣寫

 series: [
          {
            data: [3008, 9010, 262],
            type: 'bar',
            barWidth: '30px',
            color: {
              type: 'linear',
              // x=0,y=1,柱子的顏色在垂直方向漸變
              x: 0,
              y: 1,
              colorStops: [
                // 0%處的顏色
                {
                  offset: 0,
                  color: '#12c2e9'
                },
                // 50%處的顏色
                {
                  offset: 0.5,
                  color: '#c471ed'
                },
                // 100%處的顏色
                {
                  offset: 1,
                  color: '#f64f59'
                }
              ],
              global: false // 缺省為 false
            },
            itemStyle: {
              normal: {
                // 設(shè)置柱子的圓角
                barBorderRadius: [18, 18, 0, 0]
              }
            }
          }
        ]

縱向漸變

 series: [
          {
            data: [120, 200, 150, 80, 333],
            type: 'bar',
            barWidth: '10px',
            itemStyle: {
              // 柱狀圖的背景色
              normal: {
                // 每個(gè)柱子的顏色即為colorList數(shù)組里的每一項(xiàng),如果柱子數(shù)目多于colorList的長度,則柱子顏色循環(huán)使用該數(shù)組
                color: function (params) {
                  var index = params.dataIndex
                  var colorList = [
                    // 漸變顏色的色值和透明度
                    // 透明度從0
                    [
                      'rgba(15,235,255,0.3)',
                      'rgba(15,235,255,0.3)',
                      'rgba(15,235,255,0.3)',
                      'rgba(15,235,255,0.3)',
                      'rgba(15,235,255,0.3)',
                      'rgba(15,235,255,0.3)',
                      'rgba(15,235,255,0.3)',
                      'rgba(13,94,208,0.3)',
                      'rgba(255,155,15,0)',
                      'rgba(253,103,96,0.3)'
                    ], // 到透明度1 ,如果需要不同的顏色直接修改不同顏色即可
                    [
                      'rgba(15,235,255,0.6)',
                      'rgba(15,235,255,0.6)',
                      'rgba(15,235,255,0.6)',
                      'rgba(15,235,255,0.6)',
                      'rgba(15,235,255,0.6)',
                      'rgba(15,235,255,0.6)',
                      'rgba(15,235,255,0.6)',
                      'rgba(13,94,208,0.6)',
                      'rgba(255,155,15,0.6)',
                      'rgba(253,103,96,0.6)'
                    ]
                  ]
                  return {
                    colorStops: [
                      {
                        offset: 0.3, // 顏色的開始位置
                        color: colorList[0][index] // 0% 處的顏色
                      },
                      {
                        offset: 0.6, // 顏色的結(jié)束位置
                        color: colorList[1][index] // 100% 處的顏色
                      }
                    ]
                  }
                }
              }
            },
            showBackground: true,
            label: {
              show: true,
              position: 'right',
              valueAnimation: true
            }
          }
        ]
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容