echarts繪制一個環形圖

其他echarts:?

echarts繪制一個柱狀圖,柱狀折線圖

?echarts繪制一個餅圖

echarts繪制一個環形圖2?

效果圖:

代碼:

<template><div class="wrapper"><!-- 環形圖 --><div ref="doughnutChart" id="doughnutChart"></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: 100, //總數showLegend: false, //是否顯示label標簽};},created() {},mounted() {},watch: {table: {handler(newVal) {if (newVal) {// 進行數據處理操作if (newVal.limitLength) this.limitLength = newVal.limitLength;this.showLegend = newVal.showLegend;//計算總數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" ? "70%" : "48.5%",this.table.legendLocation == "left" ? "50%" : "50%").adjustedLeft,top: this.$common.adjustOffset(this.totalNum,this.table.legendLocation == "left" ? "70%" : "48.5%",this.table.legendLocation == "left" ? "50%" : "50%").adjustedTop,textStyle: {color: "#333333",fontSize: "22",fontWeight: "600",textAlign: "center", // 設置標題居中對齊},},{show: this.showTotalNum,text: "總計",left: this.$common.adjustOffset("總計",this.table.legendLocation == "left" ? "70.5%" : "48.5%",this.table.legendLocation == "left" ? "37.5%" : "37.5%").adjustedLeft,top: this.$common.adjustOffset("總計",this.table.legendLocation == "left" ? "70.5%" : "46.5%",this.table.legendLocation == "left" ? "37.5%" : "37.5%").adjustedTop,textStyle: {color: "#333333",fontSize: "12",fontWeight: "500",textAlign: "center", // 設置標題居中對齊},},],//顏色注釋顯示的位置legend: {orient:this.table.legendLocation == "left" ? "vertical" : "horizontal",// right: 10,// top: "center",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[0].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",center:this.table.legendLocation == "left"? ["72%", "50%"]: ["50%", "46%"],radius:this.table.legendLocation == "left"? ["50%", "70%"]: ["42%", "62%"], //餅圖的半徑,第一項是內半徑,第二項是外半徑avoidLabelOverlap: false,itemStyle: {color: (params) => {let index = params.dataIndex;return this.table.color[index];},},label: {show: this.showLegend,position: "outer",formatter: "{c}",},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.doughnutChart;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;#doughnutChart {width: 100%;height: 100%;box-sizing: border-box;position: absolute;top: 0;left: 0;}
}
</style>

調用:

<DoughnutChart:table="table":style="{ height: heightNew }"
/>
// table
/*** {"datas": [{"NAME": "南京醫科大學康達學院","VALUE": 20},{"NAME": "江蘇護理職業學院","VALUE": 25},{"NAME": "無錫太湖學院","VALUE": 16},{"NAME": "江蘇醫藥職業學院","VALUE": 47},{"NAME": "安徽省淮北衛生學校","VALUE": 5},{"NAME": "江蘇衛生健康職業學院","VALUE": 10},{"NAME": "太湖創意職業技術學院","VALUE": 2}],"color": ["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc","#8364FF","#36F4D7","#FBB03C"],"showPercentage": true,"showLegend": true,"showTotalNum": true,"limitLength": 10
}*/

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/208934.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/208934.shtml
英文地址,請注明出處:http://en.pswp.cn/news/208934.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

深入理解Spring Kafka中@KafkaListener注解的參數與使用方式

Apache Kafka作為一個強大的消息代理系統&#xff0c;與Spring框架的集成使得在分布式應用中處理消息變得更加簡單和靈活。Spring Kafka提供了KafkaListener注解&#xff0c;為開發者提供了一種聲明式的方式來定義消息監聽器。在本文中&#xff0c;我們將深入探討KafkaListener…

C++STL的string(超詳解)

文章目錄 前言C語言的字符串 stringstring類的常用接口string類的常見構造string (const string& str);string (const string& str, size_t pos, size_t len npos); capacitysize和lengthreserveresizeresize可以刪除數據 modify尾插插入字符插入字符串 inserterasere…

Linux lprm命令教程:如何取消打印任務(附案例詳解和注意事項)

Linux lprm命令介紹 lprm命令是Linux系統中的一個命令&#xff0c;全稱為"line printer remove"&#xff0c;用于取消已經排隊等待打印的打印任務。如果沒有提供任何參數&#xff0c;那么將會取消默認目標上的當前任務。你可以指定一個或多個作業ID號來取消這些作業…

HTML5 Audio/Video 標簽、屬性、方法、事件匯總(詳細)

文章目錄 HTML 音頻/視頻 方法HTML 音頻/視頻屬性HTML 音頻/視頻事件代碼展示如下事件代碼&#xff1a; HTML 音頻/視頻 方法 方法描述addTextTrack()向音頻/視頻添加新的文本軌道。canPlayType()檢測瀏覽器是否能播放指定的音頻/視頻類型。load()重新加載音頻/視頻元素。play…

如何將騰訊混元大模型AI接入自己的項目里(中國版本ChatGPT)

如何將騰訊混元大模型AI接入自己的項目里 一、騰訊混元大模型API二、使用步驟1、接口2、請求參數3、請求參數示例4、接口 返回示例 三、 如何獲取appKey和uid1、申請appKey:2、獲取appKey和uid 四、重要說明 一、騰訊混元大模型API 基于騰訊混元大模型AI的智能文本對話AI機器人…

【1day】泛微e-office OA系統UserSelect接口SQL 注入漏洞學習

注:該文章來自作者日常學習筆記,請勿利用文章內的相關技術從事非法測試,如因此產生的一切不良后果與作者無關。 目錄 一、漏洞描述 二、影響版本 三、資產測繪 四、漏洞復現

TypeScript 的修飾符(modifier)和裝飾器(decorator)

裝飾器是一種特殊類型的聲明&#xff0c;它能夠被附加到類聲明....上。 裝飾器使用 expression這種形式

使用消息隊列遇到的問題—kafka

目錄 1 分區2 消費者3 Kafka 如何保證消息的消費順序&#xff1f;3.1 方案一3.2 方案二 4 消息積壓 在項目中使用kafka作為消息隊列&#xff0c;核心工作是創建生產者—包裝數據&#xff1b;創建消費者----包裝數據。 欠缺一些思考&#xff0c;特此梳理項目中使用kafka遇到的一…

淺析以太網接口及串口轉以太網技術

淺析以太網接口 以太網相關接口主要包括&#xff1a;MII/RMII/SMII以及GMII/RGMII/SGMII接口。 一、MII接口 MII&#xff08;Media Independent Interface&#xff09;介質無關接口或稱為媒體獨立接口&#xff0c;它是IEEE-802.3定義的以太網行業標準。它包括一個數據接口和…

卷積詳解和并行卷積

ps&#xff1a;在 TensorFlow Keras 中&#xff0c;構建 Sequential 模型的正確方式是將層作為列表傳遞&#xff0c;而不是作為一系列單獨的參數。 modelmodels.Sequential([layers&#xff0c;layers]) 而不是modelmodels.Sequential(layers&#xff0c;layers) 文章目錄 卷積…

Redis 基礎—Redis Desktop Manager(Redis可視化工具)安裝及使用教程

Redis Desktop Manager 是一個可視化的 Redis 數據庫管理工具&#xff0c;可以方便地查看和操作 Redis 數據庫。使用 Redis Desktop Manager 可以大大提高 Redis 數據庫的管理效率。 RDM的安裝和配置 首先&#xff0c;您需要下載和安裝Redis Desktop Manager。 安裝完成后&am…

Python 小紅書評論區采集 小紅薯xhs精準用戶獲客

成品圖 評論接口https://edith.xiaohongshu.com/api/sns/web/v2/comment/page?note_id筆記id&cursor光標 初次使用cursor為空,該接口為GET&#xff0c;需要x-s,x-t簽名驗證 子評論接口https://edith.xiaohongshu.com/api/sns/web/v2/comment/sub/page?note_id%s&r…

python爬取robomaster論壇文章數據,攜帶登錄信息

一. 內容簡介 python爬取robomaster論壇文章數據。 二. 軟件環境 2.1vsCode 2.2Anaconda version: conda 22.9.0 2.3代碼 三.主要流程 3.1 接口分析&#xff0c;以及網頁結構分析 # 這是文章鏈接,其實id就是文章的id # https://bbs.robomaster.com/forum.php?modview…

win系統一臺電腦安裝兩個不同版本的mysql教程

文章目錄 1.mysql下載zip包&#xff08;地址&#xff09;2.解壓在你的電腦上&#xff08;不要再C盤和帶中文的路徑&#xff09;3.創建my.ini文件4.更改環境變量&#xff08;方便使用, 可選&#xff09;5.打包mysql服務6.初始化mysql的data7.啟動剛剛打包的服務8.更改密碼 1.mys…

CentOS常用基礎命令大全(linux命令)2

CentOS常用基礎命令大全&#xff08;linux命令&#xff09; 1.關機 (系統的關機、重啟以及登出 ) 的命令 shutdown -h now 關閉系統(1) init 0 關閉系統(2) telinit 0 關閉系統(3) shutdown -h hours:minutes & 按預定時間關閉系統 shutdown -c 取消按預定時間關閉系統 sh…

【無標將列表中的多組參數依次帶入指定的函數將每次調用函數返回結果組成列表itertools.starmap()題】

【小白從小學Python、C、Java】 【計算機等考500強證書考研】 【Python-數據分析】 將列表中的多組參數 依次帶入指定的函數 將每次調用函數 返回結果組成列表 itertools.starmap() [太陽]選擇題 請問以下代碼輸出的結果是&#xff1f; import itertools a [(1, 2), (3, 4)] p…

基于JAVA+SpringBoot+Vue的前后端分離的醫院信息智能化HIS系統

?全網粉絲20W,csdn特邀作者、博客專家、CSDN新星計劃導師、java領域優質創作者,博客之星、掘金/華為云/阿里云/InfoQ等平臺優質作者、專注于Java技術領域和畢業項目實戰? &#x1f345;文末獲取項目下載方式&#x1f345; 一、項目背景介紹&#xff1a; 隨著科技的不斷發展&a…

解決Ubuntu16.04沒聲音

第一步&#xff1a;安裝 PulseAudio Volum Control Ubuntu沒有聲音&#xff08;聽不到聲音&#xff09;的解決方法 第二步&#xff1a;No cards available for configuration 【解決Ubuntu18.04沒聲音&#xff1a;No cards available for configuration】 完美解決&#xf…

【WPF.NET開發】WPF中的對話框

目錄 1、消息框 2、通用對話框 3、自定義對話框 實現對話框 4、打開對話框的 UI 元素 4.1 菜單項 4.2 按鈕 5、返回結果 5.1 模式對話框 5.2 處理響應 5.3 非模式對話框 Windows Presentation Foundation (WPF) 為你提供了自行設計對話框的方法。 對話框是窗口&…

浙政釘SDK安裝

專有訂單SDK&#xff08;jar包&#xff09;下載 專有釘釘門戶 (dg-work.cn) Maven依賴 浙政釘 <!-- 浙政釘 --> <dependency><groupId>com.oracel</groupId><artifactId>zwdd-sdk-java</artifactId><version>1.2.0</version…