vue+Highcharts绘制3D饼图

效果图

一、下载highcharts插件

TypeScript 复制代码
npm install highcharts

二、main.js全局配置插件

TypeScript 复制代码
import Highcharts from "highcharts/highcharts";
import highcharts3d from "highcharts/highcharts-3d";
highcharts3d(Highcharts);

三、封装highcharts.vue组件

TypeScript 复制代码
Highcharts.chart("EchartsPie", {
        chart: {
          type: "pie", //饼图
          options3d: {
            enabled: true, //使用3d功能
            alpha: 70, //延y轴向内的倾斜角度
            beta: 0,
          },
          backgroundColor: "rgba(0, 0, 0, 0)", // 不显示背景色
          width: 520,
          height: 220, //设置大小是为了饼图能在想要的区域中显示
        },
        legend: {
          bottom: "0%",
          itemStyle: {
            //图例文字的样式
            color: "#999",
            fontSize: 10,
          },
          left: "center",
          itemWidth: 100,
          // doesn't perfectly work with our tricks, disable it
          selectedMode: false,
          data: this.dataList.map((item, index) => {
            item.icon = "circle";
            return item;
          }),
        },
        title: {
          text: "", //图表的标题文字
        },
        subtitle: {
          text: "", //副标题文字
        },
        plotOptions: {
          pie: {
            allowPointSelect: true, //每个扇块能否选中
            cursor: "pointer", //鼠标指针
            size: 150,
            showInLegend: true, // 是否显示图例
            depth: 35, //饼图的厚度
            dataLabels: {
              enabled: true, //是否显示饼图的线形tip
              distance: 30, //设置引导线的长度
              color: "#999", //全局设置字体颜色
              style: {
                textOutline: "none", //去掉文字白边
                fontSize: "12",
              },
              formatter: function () {
                return this.point.name + this.y + "%";
              },
            },
          },
        },
        credits: {
          enabled: false, //禁用版权url    此处不设置
        },
        series: [
          {
            type: "pie",
            name: "", //统一的前置词,非必须
            data: [
              { name: "测试1:", y: 6.3, color: "#388D60" },
              { name: "测试2:", y: 2.3, color: "#BEB84C" },
              { name: "测试3:", y: 2.3, color: "#3A55B0" },
              { name: "测试4:", y: 9.3, color: "#7B40A5" },
              { name: "测试5:", y: 0.0, color: "#B76B3D" },
            ],
            startAngle: 0, //调整饼图的角度   方向:顺时针
            label: {
              show: true,
              position: "outside",
              formatter: "{b}:{d}%",
              normal: {
                show: true,
                fontSize: 14,
                formatter: ["  {a|{b}:{d}%}"].join("\n"), //用\n来换行
                rich: {
                  a: {
                    left: 20,
                    padding: [0, -140, 0, -180], //位置按需要调整
                  },
                },
              },
            },
          },
        ],
      });

四、页面调用

TypeScript 复制代码
import EchartsBtD from "./components/echarts.bt3d.vue";
export default {
  components: { EchartsBtD },
  name: "top",
  data() {
    return {
      dataList: [
        {
          name: "综掘工作面",
          y: 25,
        },
        {
          name: "皮带机头",
          y: 11,
        },
        {
          name: "马头门",
          y: 22,
        },
        {
          name: "综采工作面",
          y: 18,
        },
        {
          name: "井底车场",
          y: 23,
        },
      ],
    };
  },
},
TypeScript 复制代码
 <EchartsBtD v-if="dataList.length != 0" :dataList="dataList"></EchartsBtD>

五、组件完整代码

TypeScript 复制代码
<template>
  <div class="echart-bt">
    <div id="EchartsPie" class="EchartsPie"></div>
  </div>
</template>
<script>
import Highcharts from "highcharts/highcharts";
import highcharts3d from "highcharts/highcharts-3d";
highcharts3d(Highcharts);
export default {
  props: ["dataList"],
  data() {
    return {
      option: {
        chart: {
          type: "pie", //饼图
          options3d: {
            enabled: true, //使用3d功能
            alpha: 70, //延y轴向内的倾斜角度
            beta: 0,
          },
          backgroundColor: "rgba(0, 0, 0, 0)", // 不显示背景色
          width: 520,
          height: 220, //设置大小是为了饼图能在想要的区域中显示
        },
        legend: {
          bottom: "0%",
          itemStyle: {
            //图例文字的样式
            color: "#999",
            fontSize: 10,
          },
          left: "center",
          itemWidth: 100,
          // doesn't perfectly work with our tricks, disable it
          selectedMode: false,
          data: this.dataList.map((item, index) => {
            item.icon = "circle";
            return item;
          }),
        },
        title: {
          text: "", //图表的标题文字
        },
        subtitle: {
          text: "", //副标题文字
        },
        plotOptions: {
          pie: {
            allowPointSelect: true, //每个扇块能否选中
            cursor: "pointer", //鼠标指针
            size: 150,
            showInLegend: true, // 是否显示图例
            depth: 35, //饼图的厚度
            dataLabels: {
              enabled: true, //是否显示饼图的线形tip
              distance: 30, //设置引导线的长度
              color: "#999", //全局设置字体颜色
              style: {
                textOutline: "none", //去掉文字白边
                fontSize: "12",
              },
              formatter: function () {
                return this.point.name + this.y + "%";
              },
            },
          },
        },
        credits: {
          enabled: false, //禁用版权url    此处不设置
        },
        series: [
          {
            type: "pie",
            name: "", //统一的前置词,非必须
            data: [
              { name: "测试1:", y: 6.3, color: "#388D60" },
              { name: "测试2:", y: 2.3, color: "#BEB84C" },
              { name: "测试3:", y: 2.3, color: "#3A55B0" },
              { name: "测试4:", y: 9.3, color: "#7B40A5" },
              { name: "测试5:", y: 0.0, color: "#B76B3D" },
            ],
            startAngle: 0, //调整饼图的角度   方向:顺时针
            label: {
              show: true,
              position: "outside",
              formatter: "{b}:{d}%",
              normal: {
                show: true,
                fontSize: 14,
                formatter: ["  {a|{b}:{d}%}"].join("\n"), //用\n来换行
                rich: {
                  a: {
                    left: 20,
                    padding: [0, -140, 0, -180], //位置按需要调整
                  },
                },
              },
            },
          },
        ],
      },
    };
  },

  watch: {},
  created() {},
  mounted() {
    this.option.series[0].data.forEach((item, index) => {
      item.name = this.dataList[index].name;
      item.y = this.dataList[index].y;
    });
    Highcharts.chart("EchartsPie", this.option);
  },
  methods: {},
};
</script> 

<style scoped>
.EchartsPie {
  width: 100%;
  height: 100%;
}
/* 禁止跳转到外部接口 */
::v-deep .highcharts-credits {
  display: none;
}

.echart-bt {
  width: 100%;
  height: 300px;
}
</style>
相关推荐
AC赳赳老秦7 小时前
外文文献精读:DeepSeek翻译并解析顶会论文核心技术要点
前端·flutter·zookeeper·自动化·rabbitmq·prometheus·deepseek
小宇的天下7 小时前
Calibre 3Dstack --每日一个命令day18【floating_trace】(3-18)
服务器·前端·数据库
毕设源码-钟学长7 小时前
【开题答辩全过程】以 基于web技术的酒店信息管理系统设计与实现-为例,包含答辩的问题和答案
前端
css趣多多7 小时前
this.$watch
前端·javascript·vue.js
Code小翊7 小时前
JS语法速查手册,一遍过JS
javascript
干前端8 小时前
Vue3虚拟滚动列表组件进阶:不定高度及原理分析!!!
前端·前端组件
子春一8 小时前
Flutter for OpenHarmony:构建一个 Flutter 天气卡片组件,深入解析动态 UI、响应式布局与语义化设计
javascript·flutter·ui
雨季6668 小时前
Flutter 三端应用实战:OpenHarmony “极简文本行数统计器”
开发语言·前端·flutter·ui·交互
有来技术8 小时前
ASP.NET Core 权限管理系统(RBAC)设计与实现|vue3-element-admin .NET 后端
vue.js·后端·c#·asp.net·.net
qq_12498707538 小时前
基于springboot的林业资源管理系统设计与实现(源码+论文+部署+安装)
java·vue.js·spring boot·后端·spring·毕业设计·计算机毕业设计