echarts的仪表盘

前端之路任重道远,这是我最近做的一个驾驶舱的仪表盘,过程实现比较繁琐,但好在效果不错,欢迎小伙伴提意见改进

 上代码,因为要多次使用所以封装成了组件

 子组件:

<template>
  <div id="gauge-chart" ref="ring" style="width: 100%; height: 100%"></div>
</template>

<script>
import * as echarts from "echarts";

export default {
  props: {
    textName: {
      type: String,
    },
    value: {
      type: Number,
    },
    color: {
      type: String,
    },
  },
  data() {
    return {};
  },
  mounted() {
    this.initEcharts(this.ringData);
  },
  created() {},
  watch: {
    ringData: {
      handler(newValue, oldValue) {
        //把新值赋值给我们的属性数据
        this.value = newValue;
        this.initEcharts(); //刷新echarts图表
      },
      deep: true,
    },
  },
  methods: {
    initEcharts() {
      // 基本柱状图
      const option = {
        title: {
          text: this.textName,
          itemGap: 3,
          x: "49%",
          y: "76%",
          textAlign: "center",
          textStyle: {
            fontWeight: "normal",
            fontSize: 12,
            color: "#555555",
          },
          subtextStyle: {
            fontWeight: "normal",
            fontSize: 12,
            color: "#555555",
            lineHeight: 14,
          },
        },
        tooltip: {
          position: "inside",
          formatter: "甲类总人数 100<br>占区域总人口 0.01%<br>鼠疫 100",
          textStyle: {
            fontSize: 10,
          },
        },
        series: [
          {
            name: "",
            type: "gauge",
            center: ["50%", "65%"],
            radius: "90%",
            min: 0, //最小刻度
            max: 100, //最大刻度
            splitNumber: 8, //刻度数量
            startAngle: 180,
            endAngle: 0,
            axisLine: {
              show: true,
              lineStyle: {
                width: 1,
                color: [[1, "rgba(0,0,0,0)"]],
              },
            }, //仪表盘轴线
            axisLabel: {
              show: false,
            }, //刻度标签。
            axisTick: {
              show: false,
            }, //

父组件传值

  <div
                style="height: 14vh; width: 100%"
                class="flex mb20 space-around"
              >
                <Dashboard
                  :textName="'甲类'"
                  :value="10"
                  :color="'#cfd409'"
                ></Dashboard>
                <Dashboard
                  :textName="'乙类'"
                  :value="50"
                  :color="'#f59a23'"
                ></Dashboard>
                <Dashboard
                  :textName="'丙类'"
                  :value="90"
                  :color="'#ff7474'"
                ></Dashboard>
              </div>


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值