echarts绘制一个环形图2

其他echarts:

echarts绘制一个环形图

echarts绘制一个柱状图,柱状折线图

echarts绘制一个饼图 

效果:

组件代码:

<template><div class="wrapper"><div ref="doughnutChart2" id="doughnutChart2"></div></div>
</template><script>
export default {mixins: [],components: {},props: {table: {type: Object,default: {datas: {},color: [],},},hollowOut: {//是否中空type: Boolean,default: false,},},data() {return {limitLength: 7, //显示name长度showTotalNum: false, //是否显示总数totalNum: 0, //总数};},created() {},mounted() {},watch: {table: {handler(newVal) {if (newVal) {// 进行数据处理操作if (newVal.limitLength) this.limitLength = newVal.limitLength;//计算总数if (newVal.showTotalNum) {this.showTotalNum = newVal.showTotalNum;this.totalNum = this.calculatePropertySum(newVal.datas, "VALUE");}const generateRandomColor = () => {var r = Math.floor(Math.random() * 201); // 随机生成红色通道值(0-200)var g = Math.floor(Math.random() * 255); // 随机生成绿色通道值(0-200)var b = Math.floor(Math.random() * 201); // 随机生成蓝色通道值(0-200)let hex ="#" + componentToHex(r) + componentToHex(g) + componentToHex(b);return hex;};const componentToHex = (c) => {let hex = c.toString(16);return hex.length == 1 ? "0" + hex : hex;};newVal.datas.map((item, index) => {if (!newVal.color[index]) {let a = generateRandomColor();newVal.color.push(a);}});setTimeout(() => {this.init();});}},},},methods: {init() {let option = {tooltip: {trigger: "item",formatter: "{b} : {c} ({d}%)",},title: [{show: this.showTotalNum,text: this.totalNum,left: this.$common.adjustOffset(this.totalNum,this.table.legendLocation == "left" ? "65%" : "47.5%",this.table.legendLocation == "left" ? "48%" : "42%").adjustedLeft,top: this.$common.adjustOffset(this.totalNum,this.table.legendLocation == "left" ? "65%" : "47.5%",this.table.legendLocation == "left" ? "48%" : "42%").adjustedTop,textStyle: {color: "#333333",fontSize: "22",fontWeight: "600",textAlign: "center", // 设置标题居中对齐},},{show: this.showTotalNum,text: "总计",left: this.$common.adjustOffset("总计",this.table.legendLocation == "left" ? "65%" : "47.5%",this.table.legendLocation == "left" ? "33%" : "29.5%").adjustedLeft,top: this.$common.adjustOffset("总计",this.table.legendLocation == "left" ? "65%" : "47.5%",this.table.legendLocation == "left" ? "33%" : "29.5%").adjustedTop,textStyle: {color: "#333333",fontSize: "12",fontWeight: "500",textAlign: "center", // 设置标题居中对齐},},],//颜色注释显示的位置legend: {orient:this.table.legendLocation == "left" ? "vertical" : "horizontal",type: "scroll", //颜色过多可以滚动left: this.table.legendLocation == "left" ? 0 : "center",top: this.table.legendLocation == "left" ? "top" : "bottom",icon: this.table.legendIcon ? "circle" : "",formatter: (name) => {let seriesData = option.series[1].data; // 数据在series的第几个中let total = 0;for (let i = 0; i < seriesData.length; i++) {total += seriesData[i].value;}for (let j = 0; j < seriesData.length; j++) {if (name === seriesData[j].name) {let percent = ((seriesData[j].value / total) * 100).toFixed(2);if (name.length > this.limitLength) {return (name.substring(0, this.limitLength) +"..." +" " +seriesData[j].value +" " +percent +"%");} else {return name + " " + seriesData[j].value + " " + percent + "%";}}}},},series: [// {//   type: "pie",//   radius: ["39%", "41%"],//   center: ["67%", "50%"],//   avoidLabelOverlap: false,//   label: {//     show: false,//     position: "center",//   },//   emphasis: {//     label: {//       show: true,//       fontSize: "30",//       fontWeight: "bold",//     },//   },//   labelLine: {//     show: false,//   },//   data: [//     {//       value: 1,//       name: undefined,//       itemStyle: {//         color: new this.$E.graphic.LinearGradient(0, 0, 0, 1, [//           { offset: 0, color: "rgba(255, 255, 255, 0)" },//           { offset: 0.24, color: "rgba(153, 140, 255, 1)" },//           { offset: 0.5, color: "rgba(117, 104, 255, 1)" },//           { offset: 0.24, color: "rgba(153, 140, 255, 1)" },//           { offset: 1, color: "rgba(255, 255, 255, 0)" },//         ]),//       },//       hoverAnimation: false,//     },//   ],//   graphic: [//     {//       type: "path",//       shape: {//         cx: 0.5,//         cy: 0.5,//         r: "15%",//       },//       style: {//         fill: "none",//         stroke: "purple",//       },//     },//   ],// },{color: ["#163d59"],type: "gauge",center:this.table.legendLocation == "left"? ["67%", "50%"]: ["50%", "40%"],startAngle: 150,endAngle: -209.999,splitNumber: 7,radius: this.table.legendLocation == "left" ? "80%" : "60%",pointer: {show: false,},progress: {show: false,roundCap: true,width: 1,},axisLine: {show: false,lineStyle: {width: 10,color: "#D7D7E3", //线的颜色},},axisTick: {distance: -25,length: 10,splitNumber: 10, //线的密度lineStyle: {width: 2, //线的宽度color: "#D7D7E3", //线的颜色},},// 隔几个变长splitLine: {show: false,},axisLabel: {show: false,},anchor: {show: false,},title: {show: false,},detail: {show: false,},data: [],},{type: "pie",center:this.table.legendLocation == "left"? ["67%", "50%"]: ["50%", "40%"],radius:this.table.legendLocation == "left"? ["60%", "85%"]: ["45%", "65%"], //饼图的半径,第一项是内半径,第二项是外半径avoidLabelOverlap: false,itemStyle: {// borderRadius: 5,borderColor: "#fff",borderWidth: 3,},label: {position: "inner",formatter: "{c}",},// emphasis: {//   label: {//     show: true,//     fontSize: 40,//     fontWeight: "bold",//   },// },data: this.table.datas.map((item, index) => {let obj = {// label: { color: this.table.color[index] },name: item.NAME,value: item.VALUE || item.NUM,};return obj;}),},],};let chartDom = this.$refs.doughnutChart2;let myChart = this.$E.init(chartDom);myChart.setOption(option);},//计算总和calculatePropertySum(arr, property) {return arr.reduce((sum, obj) => {const value = parseFloat(obj[property]);if (!isNaN(value)) {return sum + value;} else {return sum;}}, 0);},},
};
</script><style scoped lang="scss">
.wrapper {width: 100%;height: 100%;position: relative;#doughnutChart2 {width: 100%;height: 100%;box-sizing: border-box;position: absolute;top: 0;left: 0;}
}
</style>

组件调用:

<DoughnutChart2 :style="{ height: heightNew }" :table="table" />
// heightNew  动态计算的高度
// table:
/*** {"datas": [{"NAME": "主任护师","VALUE": 10},{"NAME": "副主任护师","VALUE": 64},{"NAME": "主管护师","VALUE": 418},{"NAME": "护师","VALUE": 397},{"NAME": "护士","VALUE": 86}],"color": ["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc","#8364FF","#36F4D7","#FBB03C"],"legendLocation": ["left"],"showTotalNum": true,"legendIcon": ["round"]
}*/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/257900.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

FCFS+SJF+HRRF

概述 Simply achieved three scheduling algorithms like FCFS、SJF and HRRF in OS 详细 一、运行效果 二、实现过程 ①FCFS void FCFS(PCB pro[], int num) {int time,doneTime;int count0,proNum1; //count为计数器&#xff0c;proNum记录当前的进程数量float sumTTime…

鸿蒙原生应用开发——分布式数据对象

01、什么是分布式数据对象 在可信组网环境下&#xff0c;多个相互组网认证的设备将各自创建的对象加入同一个 sessionId&#xff0c;使得加入的多个数据对象之间可以同步数据&#xff0c;也就是说&#xff0c;当某一数据对象属性发生变更时&#xff0c;其他数据对象会检测到这…

LLM之Agent(三):HuggingGPT根据用户需求自动调用Huggingface合适的模型

​ 浙大和微软亚洲研究院开源的HuggingGPT&#xff0c;又名JARVIS&#xff0c;它可以根据用户的自然语言描述的需求就可以自动分析需要哪些AI模型&#xff0c;然后去Huggingface上直接调用对应的模型&#xff0c;最终给出用户的解决方案。 一、HuggingGPT的工作流程 它的…

harmony开发之Text组件的使用

TextInput、TextArea是输入框组件&#xff0c;通常用于响应用户的输入操作&#xff0c;比如评论区的输入、聊天框的输入、表格的输入等&#xff0c;也可以结合其它组件构建功能页面&#xff0c;例如登录注册页面。 图片来源黑马程序员 Text组件的使用&#xff1a; 文本显示组…

FastAPI之请求头

请求头 FastAPI是一个现代、快速&#xff08;高性能&#xff09;、异步的Python Web框架&#xff0c;用于构建RESTful APIs。它基于标准的Python类型提示&#xff0c;并且可以生成交互式的API文档。 在本教程中&#xff0c;我们将学习如何使用FastAPI处理请求头&#xff08;H…

智能优化算法应用:基于北方苍鹰算法无线传感器网络(WSN)覆盖优化 - 附代码

智能优化算法应用&#xff1a;基于北方苍鹰算法无线传感器网络(WSN)覆盖优化 - 附代码 文章目录 智能优化算法应用&#xff1a;基于北方苍鹰算法无线传感器网络(WSN)覆盖优化 - 附代码1.无线传感网络节点模型2.覆盖数学模型及分析3.北方苍鹰算法4.实验参数设定5.算法结果6.参考…

git-vscode

git-vscode ctrlshiftp 创建分支 create branch 直接切到新的分支了 切换分支 直接点左下角自己选择 vscode中配置仓库 https://blog.csdn.net/zora_55/article/details/129709251 推送tag tag作用就是在 Git 中&#xff0c;标记存储库历史记录中特定提交的一种方式。t…

C语言之动态内存管理(malloc calloc realloc)

C语言之动态内存管理 文章目录 C语言之动态内存管理1. 为什么要有动态内存管理2. malloc 和 free2.1 malloc2.2 free2.3 例子 3. calloc 和 realloc3.1 calloc3.2 realloc 4. 常见的动态内存错误4.1 对NULL指针的解引⽤操作4.2 对动态开辟空间的越界访问4.3 对⾮动态开辟内存使…

华三AC+AP部署无线基本配置

拓扑图&#xff1a; 1、创建管理VLAN与AP管理VLAN、终端接入VLAN、配置管理VLAN IP地址 设备管理VLAN 56、AP管理VLAN 101、终端接入VLAN 10 AC、HeXin、JieRu。&#xff08;创建VLAN&#xff09;[H3C]vlan 101[H3C-vlan101]description AP-vlan[H3C]vlan 56[H3C-vlan56]desc…

OpenCL学习笔记(一)开发环境搭建(win10+vs2019)

前言 异构编程开发&#xff0c;在高性能编程中有重要的&#xff0c;笔者本次只简单介绍下&#xff0c;如何搭建简单的开发环境&#xff0c;可以供有需要的小伙伴们开发测试使用 一、获取opencl的sdk库 1.使用cuda库 若本机有Nvidia的显卡&#xff0c;在安装cuda库后&#x…

【洛谷】更换头像

错误展示 今天换头像的时候发现一直换不了&#xff0c;即使显示修改成功&#xff0c;然后我等了半个多小时也还没换好 解决办法 上传成功头像后&#xff0c;按ctrl F5 结果 更新成功&#xff01;

题目:分糖果(蓝桥OJ 2928)

题目描述&#xff1a; 解题思路&#xff1a; 本题采用贪心思想 图解 题解&#xff1a; #include<bits/stdc.h> using namespace std;const int N 1e6 9; char s[N];//写字符串数组的一种方法,像数组一样***int main() {int n, x;cin >> n >> x;for(int …