echarts柱状图

6 篇文章 0 订阅
6 篇文章 0 订阅

在这里插入图片描述

    <el-row type="flex" align="middle" justify="space-around">
      <el-col :span="8" class="list_box">
        <div class="mf_box" :style="{ top: maxValue1 - 80 + 'px' }">满分40</div>
        <div class="canvas" ref="charts1"></div>
        <div class="fh_box">建筑防火</div>
      </el-col>
      <el-col :span="8" class="list_box">
        <div class="mf_box" :style="{ top: maxValue2 - 30 + 'px' }">
          满分30
        </div>
        <div class="canvas" ref="charts2"></div>
        <div class="fh_box">消防设施与器材</div>
      </el-col>
      <el-col :span="8" class="list_box">
        <div class="mf_box" :style="{ top: maxValue2 - 30 + 'px' }">
          满分30
        </div>
        <div class="canvas" ref="charts3"></div>
        <div class="fh_box">消防安全管理</div>
      </el-col>
    </el-row>
export default {
  name: "",
  data() {
    return {
      colorList1: [
        "rgba(0,191,255)",
        "rgba(0,161,212)",
        "rgba(0,161,212)",
        "rgba(0,88,187)",
        "rgba(11,52,125)"
      ],
      colorList2: [
        "rgba(197,134,0)",
        "#C58600",
        "rgba(212,144,0)",
        "rgba(218,179,0)",
        "rgba(11,52,125)"
      ],
      maxValue1: 80,
      maxValue2: 60,
      value1: 32,
      value2: 20,
      value3: 15
    };
  },
  created() {
    this.$nextTick(() => {
      this.initCharts(
        this.$refs["charts1"],
        this.colorList1,
        this.value1,
        this.maxValue1
      );
      this.initCharts(
        this.$refs["charts2"],
        this.colorList2,
        this.value2,
        this.maxValue2
      );
      this.initCharts(
        this.$refs["charts3"],
        this.colorList1,
        this.value3,
        this.maxValue2
      );
    });
  },
  methods: {
    initCharts(charts, colorList, value, maxValue) {
      let myChart = echarts.init(charts);
      window.addEventListener("resize", function() {
        myChart.resize();
      });
      myChart.setOption({
        grid: {
          bottom: "10%",
          top: "10%",
          right: "0%",
          left: "0%"
        },

        xAxis: {
          data: [],
          axisTick: {
            show: false
          },
          axisLine: {
            show: false
          }
        },
        yAxis: {
          splitLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          axisLine: {
            show: false
          },
          axisLabel: {
            show: false
          }
        },
        series: [
          {
            name: "",
            type: "pictorialBar",
            symbolSize: [50, 15],
            symbolOffset: [0, -7],
            z: 12,
            data: [
              {
                name: "",
                value: value * 2,

                symbolPosition: "end",
                itemStyle: {
                  normal: {
                    color: colorList[0] //内部圆柱 顶部颜色
                  }
                }
              }
            ]
          },
          {
            name: "",
            type: "pictorialBar",
            symbolSize: [50, 15],
            symbolOffset: [0, 6],
            z: 12,
            data: [
              {
                name: "",
                value: value,

                itemStyle: {
                  normal: {
                    color: colorList[1] //内部圆柱 底部颜色
                  }
                }
              }
            ]
          },
          {
            type: "bar",
            // silent: true,
            barWidth: 50,
            data: [
              {
                name: "",
                value: value * 2,
                label: {
                  normal: {
                    show: true,
                    formatter: function(value, index) {
                      return ((value.value / maxValue) * 100).toFixed(0) + "%";
                    },
                    position: ["102%", "-20%"],
                    distance: 10,
                    textStyle: {
                      color: "#2CFFDB", //百分比 文字颜色
                      fontSize: 12,
                      fontWeight: 600
                    }
                  }
                },
                itemStyle: {
                  normal: {
                    color: {
                      x: 0,
                      y: 0,
                      x2: 0,
                      y2: 1,
                      type: "linear",
                      global: false,
                      colorStops: [
                        {
                          offset: 0,
                          color: colorList[2]
                        },
                        {
                          offset: 1,
                          color: colorList[3] //内部圆柱 侧面 颜色
                        }
                      ]
                    }
                  }
                }
              }
            ]
          },
          //往上是内部柱状图
          //往下是外部柱状图
          {
            name: "",
            type: "pictorialBar",
            symbolSize: [25, 10],
            symbolOffset: [0, -7],
            z: 12,
            data: [
              {
                name: "",
                value: maxValue - 1,
                symbolPosition: "end",
                itemStyle: {
                  normal: {
                    color: "rgba(0,191,255,0.2)",
                    borderColor: colorList[4], // 设置边框颜色
                    borderWidth: 1 // 设置边框宽度
                  }
                }
              }
            ]
          },
          {
            name: "",
            type: "pictorialBar",
            symbolSize: [50, 20],
            symbolOffset: [0, -10],
            z: 12,
            data: [
              {
                name: "",
                value: maxValue,

                symbolPosition: "end",
                itemStyle: {
                  normal: {
                    color: "rgba(0,191,255,0.2)" //圆柱顶部颜色 0.190.255
                  }
                }
              }
            ]
          },
          {
            name: "",
            type: "pictorialBar",
            symbolSize: [53, 18],
            symbolOffset: [0, 10],
            z: 12,
            data: [
              {
                name: "",
                value: maxValue,

                itemStyle: {
                  normal: {
                    color: colorList[1], // 虚线与内圆柱中间的 底颜色
                    borderColor: "rgba(0,88,187)", // 设置边框颜色
                    borderWidth: 1 // 设置边框宽度
                  }
                }
              }
            ]
          },
          {
            name: "",
            type: "pictorialBar",
            symbolSize: [70, 30],
            symbolOffset: [0, 15],
            z: 10,
            data: [
              {
                name: "",
                value: "100",

                itemStyle: {
                  normal: {
                    color: "transparent",
                    borderColor: "rgb(5,142,188)", //底部虚线外圆圈颜色
                    borderType: "dashed",
                    borderWidth: 2
                  }
                }
              }
            ]
          },
          {
            type: "bar",
            silent: true,
            barWidth: 50,
            barGap: "-100%",
            data: [
              {
                name: "",
                value: maxValue,

                label: {
                  normal: {
                    show: false
                  }
                },
                itemStyle: {
                  normal: {
                    color: {
                      x: 1,
                      y: 1,
                      x2: 1,
                      y2: 0,
                      type: "linear",
                      global: false,
                      colorStops: [
                        {
                          offset: 0,
                          color: "rgba(7,30,63, 0)"
                        },
                        {
                          offset: 0.3,
                          color: "rgba(2,40,118, 0.5)"
                        },
                        {
                          offset: 0.5,
                          color: "rgba(2,40,118, 0.5)"
                        },
                        {
                          offset: 0.8,
                          color: "rgba(2,40,118, 0.5)"
                        },
                        {
                          offset: 1,
                          color: "rgba(2,40,118, 1)" //外部圆柱 侧面颜色
                        }
                      ]
                    }
                  }
                }
              }
            ]
          },
          {
            //上部立体柱
            stack: "1",
            type: "bar",
            label: {
              show: true,
              position: "top",
              distance: maxValue,
              color: "#fff", // 顶部文字颜色
              fontSize: 16
            },
            silent: true,
            barWidth: 50,

            data: [
              {
                name: "",
                value: value,
                itemStyle: {
                  color: "rgba(255, 0, 0, 0)" //透明
                }
              }
            ],
            z: 12
          }
        ]
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.score_box {
  background: url(/img/kanban/aqyh/border_bg1.png) no-repeat center center;
  background-size: 100% 100%;
  position: absolute;
  height: 32.75%;
  width: 23.45%;
  top: 24.2rem;
  left: 1.5rem;
  z-index: 100;
  .title {
    height: 3rem;
    padding-left: 1.18rem;
    font-size: 18px;
    font-family: PingFangSC, PingFang SC;
    font-weight: 600;
    color: #ffffff;
    padding-top: 1.37rem;
    img {
      margin-right: 0.56rem;
    }
  }
  .list_box {
    display: flex;
    align-items: center;
    flex-direction: column;
    position: relative;
    .mf_box {
      width: 52px;
      height: 18px;
      background: rgba(0, 88, 178, 0.28);
      border-radius: 2px;
      line-height: 18px;
      text-align: center;
      font-size: 12px;
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      color: #15ffd5;
      margin-top: 26px;
      position: relative;
    }
    .fh_box {
      font-size: 14px;
      font-family: PingFangSC, PingFang SC;
      font-weight: 500;
      color: #ffffff;
      margin-top: 10px;
    }
    .canvas {
      width: 120px;
      height: 160px;
    }
  }
}
</style>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值