echarts vue里画一个简单的环状饼图

19 篇文章 1 订阅

        <!--观察记录-->
        <div class="teach-plan observe-record">
          <div class="title-common">
            <div class="title-common-left">
              观察记录
            </div>
          </div>
          <div class="teach-plan-cont">
            <div class="tpc-lef">
              <div class="tpc-lef-list">
                <div class="d1">观察记录数</div>
                <div class="d2">300</div>
              </div>
              <div class="tpc-lef-list">
                <div class="d1">观察幼儿</div>
                <div class="d2">30</div>
              </div>
              <div class="tpc-lef-list">
                <div class="d1">记录班级</div>
                <div class="d2">3</div>
              </div>
            </div>
            <div class="tpc-rig">
              <div class="pie-box">
                <div class="d1" id="completionRate" style="width: 66px; height: 66px;"></div>
                <div class="d2">完成人数占比</div>
              </div>
            </div>
          </div>
        </div>
        <!--观察记录-end-->

  data() {
    return {
      chartdom: null,
    };
  },

  mounted() {
    this.pieEcharts();
  },

methods里:

    pieEcharts() {
      const container = document.getElementById('completionRate'); // 获取容器元素
      this.chartdom = echarts.init(container); // 初始化echarts实例
      let correctRate = 80
      let errorRate = 20
      var option = {
        tooltip: {
          show: false,
          trigger: 'item',
          formatter: "{a} : {c} ({d}%)"
        },
        title: {
          text: correctRate + '%',  //图形标题,配置在中间对应效果图的80%
          left: "center",
          top: "35%",
          textStyle: {
            color: "#299bff",
            fontSize: 16,
            align: "center"
          }
        },
        series: [
          {
            type: 'pie',
            radius: ['86%', '98%'],  //设置内外环半径,两者差值越大,环越粗
            hoverAnimation: false,  //移入图形是否放大
            label: {     //对应效果图中的Angular显示与否以及设置样式
              // show: true,
              // position: 'center',
              normal: {
                show: true,
                position: 'center',
                padding: [0, 0, 20, 0],  //设置字angular的边距
                fontSize: 16,
              }
            },
            labelLine: {
              normal: {  //label线不显示
                show: false
              }
            },
            data: [
              {
                value: correctRate,  //对应显示的部分数据即80%
                itemStyle: {
                  normal: {
                    color: '#299bff',
                  }
                }
              },
              {
                value: errorRate,
                itemStyle: {
                  normal: {
                    color: '#edeef0'
                  }
                }
              }
            ]
          }
        ]
      };

      this.chartdom.setOption(option);
      //随着屏幕大小调节图表
      //myChart.resize();
      window.addEventListener('resize', () => {
        this.chartdom.resize();
      });
    },

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用 EChartsVue 3 来实现柱状饼图的定时联动。首先,你需要安装并引入 EChartsVue 3 的相关依赖。 接下来,你可以创建一个 Vue 组件来显示柱状饼图,并使用定时器来更新数据。以下是一个简单的示例代码: ```vue <template> <div> <div ref="barChart" style="width: 600px; height: 400px;"></div> <div ref="pieChart" style="width: 600px; height: 400px;"></div> </div> </template> <script> import * as echarts from 'echarts'; export default { data() { return { barChart: null, pieChart: null, barData: [], // 柱状数据 pieData: [] // 饼图数据 }; }, mounted() { // 初始化柱状饼图 this.barChart = echarts.init(this.$refs.barChart); this.pieChart = echarts.init(this.$refs.pieChart); // 定时更新数据 setInterval(() => { this.updateData(); }, 5000); // 初始化数据 this.updateData(); }, methods: { updateData() { // 模拟异步获取数据 setTimeout(() => { // 更新柱状数据 this.barData = [ { name: 'A', value: Math.random() * 100 }, { name: 'B', value: Math.random() * 100 }, { name: 'C', value: Math.random() * 100 } ]; // 更新饼图数据 this.pieData = [ { name: 'A', value: Math.random() * 100 }, { name: 'B', value: Math.random() * 100 }, { name: 'C', value: Math.random() * 100 } ]; // 更新柱状 this.barChart.setOption({ xAxis: { data: this.barData.map(item => item.name) }, series: [{ data: this.barData.map(item => item.value) }] }); // 更新饼图 this.pieChart.setOption({ series: [{ data: this.pieData }] }); }, 500); } } }; </script> ``` 在上面的示例代码中,我们使用了 ECharts 的 `init` 方法来初始化柱状饼图,并使用定时器来更新数据。在 `updateData` 方法中,我们模拟异步获取数据,并根据数据更新柱状饼图。 注意,上面的示例代码是一个简单的示例,你可以根据自己的需求修改和扩展。同时,你需要根据实际情况安装和引入正确的 EChartsVue 3 的相关依赖。 希望能帮到你!如有其他问题,请继续提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值