首页 > 其他分享 >echarts电池柱形图

echarts电池柱形图

时间:2023-05-17 11:37:38浏览次数:34  
标签:color 100% 柱形图 电池 159 params let data echarts

 

 <div class="aside-echarts lastPosition-wrap">
          <div
            class="echarts"
            id="lastPositionEchat"
            ref="lastPositionEchat"
            :style="'height:' + height + 'px'"
          ></div>
        </div>

 

 

 getLastPositionData() {
      let xlist = [];
      let xlist2 = [];
      let _this = this;
 
      var data = {
        name: [
          '计算存储集群',
          '某某卡口备注名称',
          '某某卡口备注名称',
          '某某卡口备注名称',
          '某某卡口备注名称',
          '公用mysql',
          '公用mysql2',
          '某某卡口备注名称2',
          '某某卡口备注名称3',
          '卡角度思考看监控',
          '啊可是觉得喀什假大空',
          '按实际的哈十九点和',
          '寄卡升级的卡进度啊实打实'
        ],
        value: [15, 25, 35, 44, 68, 67, 69, 70, 70, 71, 88, 120, 159],
        totalValue: [
          159,
          159,
          159,
          159,
          159,
          159,
          159,
          159,
          159,
          159,
          159,
          159,
          159
        ],
        color: [
          ['#F83600', '#FE8C00'],
          ['#B993D6', '#F7971E'],
          ['#EC008C', '#FC6767'],
          ['#0CEBEB', '#29FFC6'],
          ['#4776E6', '#8E54E9'],
          ['#FFD200', '#F7971E'],
          ['#00D2FF', '#3A7BD5']
        ],
        colorList: []
      };
      this.height = data.name.length * 40;
      let i = 0;
      let numList = [];
      for (let a = 0; a < data.name.length; a++) {
        if (i == 7) {
          i = 0;
        }
        console.log(1, data.color[i]);
        data.colorList.push(data.color[i]);
        i++;
      }
      setTimeout(_ => {
        let myChart = _this.$echarts.init(_this.$refs.lastPositionEchat);
        myChart.resize();
        myChart.setOption({
          grid: {
            left: 30,
            right: 20,
            top: 19,
            bottom: 0,
            containLabel: true
          },
          xAxis: {
            type: 'value',
            splitLine: {
              //去除网格线
              show: false
            },
            axisLabel: {
              show: false
            },
            axisLine: {
              //坐标轴线条相关设置(颜色等)
              show: false
            }
          },
          yAxis: {
            name: '',
            type: 'category',
            axisLine: {
              show: false
            },
            axisTick: {
              //不显示刻度线
              show: false
            },
            axisLabel: {
              textStyle: {
                color: '#51D7FF',
                fontSize: 13,
                padding: [0, 5, 0, 0]
              }
            },
            data: data.name
          },
          series: [
            {
              type: 'bar',
              itemStyle: {
                //---图形形状
                normal: {
                  color: function(params) {
                    console.log(params, 'pppppppppppppppppppppp', params.data);
                    let colorList = data.colorList;
                    var colorItem = colorList[params.dataIndex];
                    return new _this.$echarts.graphic.LinearGradient(
                      1,
                      0,
                      0,
                      0,
                      [
                        {
                          offset: 0,
                          color: colorItem[0]
                        },

                        {
                          offset: 1,
                          color: colorItem[1]
                        }
                      ],

                      false
                    );
                  }
                }
              },
              barWidth: 15, //---柱形宽度
              barCategoryGap: 94, //---柱形间距
              data: data.value,
              z: 1,
              zlevel: 2
            },
            {
              type: 'bar',
              barWidth: 15,
              barGap: '-100%',
              data: data.totalValue.map(function(item, index) {
                return {
                  value: item,
                  realValue: data.value[index],
                  color: data.colorList[index][0]
                };
              }),
              //每行数值
              label: {
                show: true,
                position: 'right',
                formatter: function(params) {
                  console.log(params);
                  return params.data.realValue;
                },
                // color: function(params) {
                //   console.log(params);
                //   return params.data.color;
                // },
                // color: ['red', 'yellow'],
                color: '#D9EAF5',
                fontSize: 12,
                padding: [0, 0, 0, 7]
              },
              itemStyle: {
                color: '#0D2C4A' //默认格子颜色
              },
              z: 0,
              zlevel: 1
            },
            {
              // 分隔
              type: 'pictorialBar',
              itemStyle: {
                normal: {
                  color: '#020C1B'
                }
              },
              symbol: 'rect',
              symbolRepeat: 'fixed',
              symbolMargin: 2,
              symbolClip: true,
              symbolSize: [5, 18],
              // symbolBoundingData: 100,
              data: data.totalValue,
              width: 2,
              z: 10,
              zlevel: 3
            }
          ]
        });
        window.addEventListener('resize', () => {
          myChart.resize();
        });
      }, 1000);
    },

 

 .lastPosition-wrap {
        width: calc(100% - 20px);
        height: calc(100% - 48px);
        overflow-y: auto;
        overflow-x: hidden;
        margin: 0 10px;
        box-sizing: border-box;
      }
.aside-echarts {
        width: 100%;
        height: calc(100% - 48px);
        .echarts {
          width: 100%;
          height: 100%;
        }
      }

 

标签:color,100%,柱形图,电池,159,params,let,data,echarts
From: https://www.cnblogs.com/ruyijiang/p/17408054.html

相关文章