echarts横条条

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

在这里插入图片描述

    <div class="canvas" ref="charts"></div>
export default {
  name: "",
  created() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  methods: {
    initChart() {
      const datas = [
        { name: "极低风险", percent: "32", finished: "5" },
        { name: "低风险", percent: "26", finished: "15" },
        { name: "中风险", percent: "40", finished: "25" },
        { name: "高风险", percent: "30", finished: "10" },
        { name: "极高风险", percent: "20", finished: "12" },
      ];
      const yData = datas.map(item => item.name);
      const zData = datas.map(item => item.finished);
      const pData = datas.map(item => item.percent);
      // 设置等长的背景柱状图
      const maxData = new Array(yData.length).fill(100);
      let myChart = echarts.init(this.$refs.charts);
      window.addEventListener("resize", function() {
        myChart.resize();
      });
      myChart.setOption({
        grid: {
          left: "22%",
          right: "8%",
          bottom: "0%",
          top: "5%",
          containLabel: false
        },
        xAxis: [
          {
            show: true
          },
          {
            splitLine: {
              show: false
            },
            axisLabel: {
              show: false
            }
          }
        ],
        yAxis: [
          {
            show: true,
            data: yData,
            position: "left",
            axisLabel: {
              lineHeight: 0,
              verticalAlign: "bottom",
              fontSize: 14,
              color: "#fff",
              formatter: "{value}"
            },
            axisLine: {
              show: false
            },
            splitLine: {
              show: false
            },
            axisTick: {
              show: false
            }
          },
          {
            show: true,
            data: zData,
            offset: 5,
            position: "right",
            axisLabel: {
              lineHeight: 0,
              verticalAlign: "bottom",
              fontSize: 14,
              color: "#0AF7B0",
              formatter: "{value}"
            },
            axisLine: {
              show: false
            },
            splitLine: {
              show: false
            },
            axisTick: {
              show: false
            }
          }
        ],
        series: [
          {
            name: "进度",
            show: true,
            type: "bar",
            barGap: "-100%",
            xAxisIndex: 1,
            barWidth: 15,
            itemStyle: {
              borderRadius: 10,
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 1,
                y2: 0,
                colorStops: [
                  {
                    offset: 0,
                    color: "#009EEC" // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "#0EFFEB" // 0% 处的颜色
                  }
                ],
                global: false // 缺省为 false
              }
            },
            label: {
              show: false,
              position: "insideRight",
              formatter: "{c}%",
              offset: [-10, 2],
              color: "#fff"
            },
            labelLine: {
              show: false
            },
            z: 2,
            data: pData,
            animationDelay: 1000,
            animationDuration: 1000
          },
          {
            name: "百分比",
            z: 1,
            show: true,
            type: "bar",
            xAxisIndex: 1,
            barGap: "-100%",
            barWidth: 15,
            itemStyle: {
              borderRadius: 10,
              color: "#074785"
            },
            label: {
              show: false
            },
            data: maxData
          }
        ]
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.city_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: 4.7rem;
  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;
    }
  }
  .canvas {
    width: 400px;
    height: 228px;
  }
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值