vue3+echarts环形柱状图

效果如下:
在这里插入图片描述

代码实现

// 环形柱状图js封装  
//chartOption.ts文件
import * as Echarts from "echarts";
export const circleOption = {
  polar: {
    // radius: [30, "80%"]
  },
  angleAxis: {
    // max: 2,
    //   startAngle: 75
    show: false
  },
  radiusAxis: {
    type: "category",
    data: ["统计"],
    show: false
  },
  tooltip: {},
  legend: {
    show: true,
    data: ["喜羊羊", "美羊羊", "懒羊羊"]
  },
  series: [
    {
      type: "bar",
      data: [] as number[],
      coordinateSystem: "polar",
      name: "喜羊羊",
      label: {
        show: true,
        position: "middle"
      },
      itemStyle: {
        borderColor: "red",
        opacity: 0.8,
        borderWidth: 1
      }
    },
    {
      type: "bar",
      data: [] as number[],
      coordinateSystem: "polar",
      name: "美羊羊",
      // roundCap: true,
      label: {
        show: true,
        position: "middle"
      },
      itemStyle: {
        borderColor: "green",
        opacity: 0.8,
        borderWidth: 1
      }
    },
    {
      type: "bar",
      data: [] as number[],
      coordinateSystem: "polar",
      name: "懒羊羊",
      // roundCap: true,
      label: {
        show: true,
        position: "middle"
      },
      itemStyle: {
        borderColor: "yellow",
        opacity: 0.8,
        borderWidth: 1
      }
    }
  ]
};

前端代码

// html
<div ref="chart4" class="word_chart"></div>
// js
const chart4 = ref();
const ChartsObj4 = shallowRef<echarts.ECharts>();
// 初始化
function initCharts() {
  window.addEventListener("resize", () => {
    ChartsObj4.value?.resize();
  });
  ChartsObj4.value = echarts.init(chart4.value);
}
/*
 接口请求 返回格式
{
'喜羊羊': 1,
'美羊羊': 3,
'懒羊羊': 1
}
*/
getCount(queryForm1).then((res: any) => {
    circleOption.series[0].data = [res.data?.'喜羊羊'];
    circleOption.series[1].data = [res.data?.'美羊羊'];
    circleOption.series[2].data = [res.data?.'懒羊羊'];
    nextTick(() => {
      ChartsObj4.value?.setOption(circleOption);
    });
  });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值