echarts自定义胶囊柱图并设置每个柱子的渐变色

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  drawCharts() {
    let myChart = echarts.init(document.getElementById('main'));
    let option = {
      tooltip: {
          trigger: 'axis',
          axisPointer: {
              type: 'line'
          }
      },
      grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
      },
      xAxis: {
          type: 'value',
          splitLine:{//坐标轴在grid区域的分割线
            show:false
          },
          axisLabel:{
            show:false
          }
      },
      yAxis: [
        {
          type: 'category',
          data: ['日发电', '月发电', '年发电'],
          inverse:true,
          axisTick: {
            alignWithLabel: true,
            show:false
          },
          axisLine:{
            show:false
          }
        },
        {
          type: 'category',
          data: [1000, 1000, 1000],
          inverse:true,
          axisTick: {
            alignWithLabel: true,
            show:false
          },
          axisLine:{
            show:false
          },
          axisLabel:{
            textStyle:{
              fontSize:12,
              color:"#fff"
            }
          }
        }
      ],
      series: [
        {
            name: '数据',
            type: 'bar',
            yAxisIndex:0,
            data: [10, 52, 20],
            barWidth: '38%',
            label:{
              show:true,
              position: 'top',
              formatter:function(params){
                return params.data+"%";
              }
            },
            // 设置每个柱子的渐变色
            itemStyle: {
                borderRadius:[0, 0, 50, 0],
                color:function(params){
                  let colorList = [
                      ['#0B42A7', '#209CFF'],
                      ['#068054', '#0DB484'],
                      ['#C86A05', '#E9B500'],
                  ]
                  let colorItem = colorList[params.dataIndex]
                  return new echarts.graphic.LinearGradient(0,0,1,0,
                    [
                      {
                        offset: 0,
                        color: colorItem[0]
                      },
                      {
                        offset: 1,
                        color: colorItem[1]
                      }
                    ], false
                  )
                }
            }
        },
        {
          name: '',
          type: 'bar',
          yAxisIndex:1, //使两个柱状图重合的效果
          barWidth: '40%',
          data: [100, 100, 100, 100, 100,100, 100],
          label:{
            show:false
          },
          itemStyle:{
            color:"none",
            borderColor:"#143670",
            borderWidth:2,
            borderRadius:[0, 0, 50, 0],
          },
        }
      ]
    }
    myChart.setOption(option);
  },
  onSelectChange(selectedRowKeys) {
    if (selectedRowKeys.length > 4) {
      this.$message.warning('最多只能选择4条缺陷!')
      return
    }
    this.selectedRowKeys = selectedRowKeys
  },
}

  

posted @   紫诺花开  阅读(134)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示