echarts堆叠、渐变、圆柱、底部发光柱状图

这种柱状图涉及到了堆叠、渐变、圆柱、底部发光等多个知识点,我找了很多资料,没有一摸一样的例子,于是我自己组合了一下,分享给大家。

先看效果图:
在这里插入图片描述
下面就让我们看看如何实现吧:
1.html中定义一个div,用来盛放柱状图

<div style="width: 500px; height: 194px" id="barChartFour"></div>

2.引入echarts

import * as echarts from "echarts";

3.js代码

getBarChart() {
      var myChart = this.echarts.init(document.getElementById("barChartFour"));
      var option = {
        backgroundColor: "rgb(0,0,0,0)",
        grid: {
          top: "15%",
          left: "1%",
          bottom: "5%",
          right: "3%",
          containLabel: true,
        },
        tooltip: {
          show: true,
          trigger: "axis",
          textStyle: {
            fontSize: 14,
          },
        },
        legend: {
          show: true,
          right:'10',
          y: "1%",
          itemWidth: 12,
          itemHeight: 12,
          textStyle: {
            color: "#fff",
            fontSize: '0.72vw',
          },
          data: ["用电负荷", "发电量"],
        },
        xAxis: [
          {
            type: "category",
            name: "",
            axisLabel: {
              interval: 0,
              textStyle: {
                color: "#319899",
                fontSize: "14",
                fontFamily: "Source Han Sans CN",
              },
            },
            axisLine: {
              lineStyle: {
                width: 2,
                color: "#086680",
              },
            },
            axisTick: {
              show: false,
            },
            splitLine: {
              show: false,
              lineStyle: {
                color: "#197584",
              },
            },
            data: this.Xdata
          },
        ],
        yAxis: [
          {
            type: "value",
            name: "MW",
            nameTextStyle: {
              fontSize: 14,
              color: '#319899',
              fontFamily: 'DIN',
              fontWeight: 'bold'
            },
            axisLabel: {
              textStyle: {
                color: "#319899",
                fontSize: "14",
              },
            },
            axisTick: {
              show: false,
            },
            axisLine: {
              lineStyle: {
                width: 2,
                color: "#086680",
              },
            },
            splitLine: {
              lineStyle: {
                color: "rgba(0,246,255,0.4)",
                type: "dashed",
              },
            },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [
          // 顶部圈
          {
            name: "",
            type: "pictorialBar",
            symbolSize: [8, 5],
            symbolOffset: [-8, -3],
            symbolPosition: "end",
            z: 12,
            tooltip: {
              show: false,
            },
            label: {
              normal: {
                show: false,
                position: "top",
                fontSize: 14,
                color: "#fff",
              },
            },
            color: "#FAD961",
            data: this.YdataOne
          },
          // 底部内圈
          {
            name: "",
            type: "pictorialBar",
            tooltip: {
              show: false,
            },
            symbolSize: [11, 6],
            symbolOffset: [-8, 5],
            z: 10,
            itemStyle: {
              normal: {
                color: "transparent",
                borderColor: "#FAD961",
                borderType: "solid",
                borderWidth: 2,
              },
            },
            data: this.YdataOne
          },
          // 底部外圈
          {
            name: "",
            type: "pictorialBar",
            tooltip: {
              show: false,
            },
            symbolSize: [18, 8],
            symbolOffset: [-8, 7],
            // z: 10,
            itemStyle: {
              normal: {
                color: "transparent",
                borderColor: "#F76B1C",
                borderType: "solid",
                borderWidth: 2,
              },
            },
            data: this.YdataOne
          },
          {
            name: "",
            type: "pictorialBar",
            symbolSize: [8, 5],
            tooltip: {
              show: false,
            },
            symbolOffset: [-8, 3],
            z: 12,
            color: "#FAD961",
            data: this.YdataOne
          },
          {
            type: "bar",
            name: "用电负荷",
            barWidth: "8",
            label: {
              normal: {
                show: false,
                position: "top",
                fontSize: 14,
                color: "#fff",
                opacity: 1,
              },
            },
            itemStyle: {
              normal: {
                color: {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: "rgba(247,107,28, 1)", // 0% 处的颜色
                    },
                    {
                      offset: 0.5,
                      color: "rgba(250,217,97, 1)", // 100% 处的颜色
                    },
                  ],
                  global: false, // 缺省为 false
                },
                opacity: 1,
              },
            },
            data: this.YdataOne
          },
          // 第二根柱子
          // 头部圆
          {
            name: "",
            type: "pictorialBar",
            symbolSize: [8, 5],
            symbolOffset: [8, -3],
            symbolPosition: "end",
            z: 12,
            tooltip: {
              show: false,
            },
            label: {
              normal: {
                show: false,
                position: "top",
                fontSize: 14,
                color: "#fff",
              },
            },
            color: "#80E5D1",
            data: this.YdataTwo
          },
          // 底部内圈
          {
            name: "",
            type: "pictorialBar",
            tooltip: {
              show: false,
            },
            symbolSize: [11, 6],
            symbolOffset: [8, 5],
            z: 10,
            itemStyle: {
              normal: {
                color: "transparent",
                borderColor: "#80E5D1",
                borderType: "solid",
                borderWidth: 2,
              },
            },
            data: this.YdataTwo
          },
          // 底部外圈
          {
            name: "",
            type: "pictorialBar",
            tooltip: {
              show: false,
            },
            symbolSize: [18, 8],
            symbolOffset: [8, 7],
            // z: 10,
            itemStyle: {
              normal: {
                color: "transparent",
                borderColor: "#005B75",
                borderType: "solid",
                borderWidth: 2,
              },
            },
            data: this.YdataTwo
          },
          // 底部圈
          {
            name: "",
            type: "pictorialBar",
            symbolSize: [8, 5],
            tooltip: {
              show: false,
            },
            symbolOffset: [8, 3],
            z: 12,
            color: "#80E5D1",
            data: this.YdataTwo
          },
          {
            type: "bar",
            name: "发电量",
            barWidth: "8",
            stack: "ke",
            barGap: "100%",
            label: {
              normal: {
                show: false,
                position: "top",
                fontSize: 14,
                color: "#fff",
              },
            },
            itemStyle: {
              normal: {
                color: {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: "rgba(0,91,117, 1)", // 0% 处的颜色
                    },
                    {
                      offset: 0.5,
                      color: "rgba(128,229,209, 1)", // 100% 处的颜色
                    },
                  ],
                  global: false, // 缺省为 false
                },
                opacity: 1,
              },
            },
            data: this.YdataTwo
          },
          {
            type: "bar",
            name: "总装机容量",
            barWidth: "8",
            stack: "ke",
            barGap: "100%",
            label: {
              normal: {
                show: false,
                position: "top",
                fontSize: 14,
                color: "#fff",
              },
            },
            itemStyle: {
              normal: {
                color: "rgb(0,91,117,0.8)",
                opacity: 1,
              },
            },
            data: this.YdataThree
          },
          {
            name: "总装机容量",
            type: "pictorialBar",
            symbolSize: [8, 5],
            symbolOffset: [8, -3],
            symbolPosition: "end",
            z: 12,
            tooltip: {
              show: false,
            },
            label: {
              normal: {
                show: false,
                position: "top",
                fontSize: 14,
                color: "#fff",
              },
            },
            color: "rgb(0,91,117,1)",
            data: this.YdataThree
          },
        ],
      };
      myChart.setOption(option);
    },

至此,便制作完成了

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值