vue echarts 扇形封装

2024-03-06 20:20

本文主要是介绍vue echarts 扇形封装,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

先上效果图:
在这里插入图片描述

有这种图的引入调用就行了

import Ring from '@/components/EchartsModule/Ring.vue'components: { Ring,},data() {return {echartsList: [{ title: '平台分析', IdName: 'Platform', XTitle: '', YTitle: '' },{ title: '城市分析', IdName: 'City', XTitle: '数量', YTitle: '城市' },{ title: '商品品牌分析', IdName: 'ProductBrand', XTitle: '数量', YTitle: '商品品牌' },{ title: '店铺品牌分析', IdName: 'StoreBrand', XTitle: '数量', YTitle: '店铺品牌' },],platformList: [{ key: "pupu", doc_count: 8978, percent: "0.10%", title: "朴朴超市" },{ key: "ddmaicai", doc_count: 18377, percent: "0.21%", title: "叮咚买菜" },{ key: "missfresh", doc_count: 23800, percent: "0.27%", title: "每日优鲜" },{ key: "hema", doc_count: 27003, percent: "0.31%", title: "盒马" },{ key: "rtmart", doc_count: 99820, percent: "1.15%", title: "大润发" },{ key: "vanguard", doc_count: 168429, percent: "1.95%", title: "华润万家" },{ key: "pdj", doc_count: 463149, percent: "5.35%", title: "京东到家" },{ key: "dmall", doc_count: 743144, percent: "8.58%", title: "多点" },{ key: "ele", doc_count: 3311648, percent: "38.25%", title: "饿了么" },{ key: "meituanwm", doc_count: 3793943, percent: "43.82%", title: "美团" },],CityList: [{ key: 110000, doc_count: 996548, percent: "28.84%", title: "北京" },{ key: 310000, doc_count: 487520, percent: "14.11%", title: "上海" },{ key: 440300, doc_count: 384457, percent: "11.13%", title: "深圳" },{ key: 441900, doc_count: 283428, percent: "8.20%", title: "东莞" },{ key: 120000, doc_count: 260665, percent: "7.54%", title: "天津" },{ key: 440100, doc_count: 236849, percent: "6.86%", title: "广州" },{ key: 320100, doc_count: 211581, percent: "6.12%", title: "南京" },{ key: 330100, doc_count: 209894, percent: "6.08%", title: "杭州" },{ key: 320500, doc_count: 203020, percent: "5.88%", title: "苏州" },{ key: 420100, doc_count: 181021, percent: "5.24%", title: "武汉1回答武2汉3武汉" },]}},
        <div class="echarts-box flexColumn" v-for="item, index in echartsList" :key="index"><div class="title-box flexRow"><p class="title-name">{{ item.title }}</p><p class="flexRow" @click="OpenRegister"><span><svg class="icon" aria-hidden="true"><use xlink:href="#iconiconmore"></use></svg></span><span>全部数据</span></p></div><div class="picture" :id="item.IdName"><Ring :ListData="platformList" :id="item.IdName" v-if="index == 0"></Ring><CylindricalY v-else :ListData="CityList" :id="item.IdName" :XName="item.XTitle" :YName="item.YTitle"></CylindricalY></div></div>

组件封装代码如下:

<template><div class="Ring-box" :id="id"></div>
</template>
<script>
export default {data() {return {}},props: {ListData: {type: Array,default: () => []},id: {type: String,default: () => 'Cylindrical'}},mounted() {this.Drawing(this.id, this.ListTidy(this.ListData.reverse()))},methods: {//画圆形图Drawing(id, list) {var that = this;var colorList = ["#73a0fa","#73deb3","#e689ee","#f7c739","#eb7e65","#83d0ef","#a285d2","#ffab67","#46a9a8","#ffa8cc","#8787C0",];// var dom = this.$refs[name];var dom = document.getElementById(id);var myChart = this.$echarts.init(dom);var option;var obj = {};//判断是否有数据if (list) {list.forEach(item => {obj[item.key] = item.value;});}const downloadJson = obj;const canvas = document.createElement("canvas");const ctx = canvas.getContext("2d");canvas.width = canvas.height = 100;ctx.textAlign = "center";ctx.textBaseline = "middle";ctx.globalAlpha = 0.08;ctx.font = "20px Microsoft Yahei";ctx.translate(50, 50);ctx.rotate(-Math.PI / 4);option = {backgroundColor: {type: "pattern",image: canvas,repeat: "repeat",},tooltip: {trigger: "item",formatter: function (e) {var { name, value } = e;value = that.NumberDealWith(value)return name + " : " + value},extraCssText: "padding:6px 10px",// position: ["center", "center"],},legend: {orient: "vertical",right: "6%",top: "center",textStyle: {color: "#303030",offset: [30, 40],},selectorLabel: {fontSize: 20,offset: [30, 40],backgroundColor: "red",},icon: "circle",itemWidth: 10,itemHeight: 10,align: "left",formatter: function (name) {var total = 0;var tarValue;for (let i = 0, l = list.length; i < l; i++) {total += list[i].value;if (list[i].key == name) {tarValue = list[i].value;}}let p = parseFloat(((tarValue / total) * 100).toFixed(2));return name + " : " + p + "%";},},series: [{type: "pie",radius: [0, "60%"],center: ["38%", "50%"],data: Object.keys(downloadJson).map(function (key) {return {name: key.replace(".js", ""),value: downloadJson[key],};}),emphasis: {itemStyle: {shadowBlur: 10,shadowOffsetX: 0,shadowColor: "rgba(0, 0, 0, 0.5)",},},label: {// position: "aside",show: false,},itemStyle: {color: function (params) {var index = params.dataIndex;var multiple = parseInt(params.dataIndex / colorList.length);if (params.dataIndex >= colorList.length) {index = params.dataIndex - multiple * colorList.length;}return colorList[index];},},},],graphic: [{type: "image",left: "25%",top: "45%",z: 100,bounding: "raw",style: {image: "https://www.o2omind.com/img/logo_syf.png",width: 144,height: 36,opacity: 0.4,},},],};this.isLoading = false;if (option && typeof option === "object") {myChart.setOption(option);}window.addEventListener('resize', (() => {myChart.resize();}))},//数据值处理NumberDealWith(number) {if (number < 9999.99) {number = parseFloat(number.toFixed(2));} else if (number < 9999.9 * 10000) {number = parseFloat((number / 10000).toFixed(1)) + "万";} else {number = parseFloat((number / 10000 / 10000).toFixed(1)) + "亿";}return number;},//数组按需整理ListTidy(list) {var Larr = [];if (list) {list.forEach((item) => {var obj = {};obj.key = item.title;obj.value = item.doc_count;Larr.push(obj);});}return Larr;},}
}
</script>
<style>
.Ring-box{width: 100%;height: 100%;
}

这篇关于vue echarts 扇形封装的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/781211

相关文章

vite搭建vue3项目的搭建步骤

《vite搭建vue3项目的搭建步骤》本文主要介绍了vite搭建vue3项目的搭建步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录1.确保Nodejs环境2.使用vite-cli工具3.进入项目安装依赖1.确保Nodejs环境

Nginx搭建前端本地预览环境的完整步骤教学

《Nginx搭建前端本地预览环境的完整步骤教学》这篇文章主要为大家详细介绍了Nginx搭建前端本地预览环境的完整步骤教学,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录项目目录结构核心配置文件:nginx.conf脚本化操作:nginx.shnpm 脚本集成总结:对前端的意义很多

前端缓存策略的自解方案全解析

《前端缓存策略的自解方案全解析》缓存从来都是前端的一个痛点,很多前端搞不清楚缓存到底是何物,:本文主要介绍前端缓存的自解方案,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录一、为什么“清缓存”成了技术圈的梗二、先给缓存“把个脉”:浏览器到底缓存了谁?三、设计思路:把“发版”做成“自愈”四、代码

通过React实现页面的无限滚动效果

《通过React实现页面的无限滚动效果》今天我们来聊聊无限滚动这个现代Web开发中不可或缺的技术,无论你是刷微博、逛知乎还是看脚本,无限滚动都已经渗透到我们日常的浏览体验中,那么,如何优雅地实现它呢?... 目录1. 早期的解决方案2. 交叉观察者:IntersectionObserver2.1 Inter

Vue3视频播放组件 vue3-video-play使用方式

《Vue3视频播放组件vue3-video-play使用方式》vue3-video-play是Vue3的视频播放组件,基于原生video标签开发,支持MP4和HLS流,提供全局/局部引入方式,可监听... 目录一、安装二、全局引入三、局部引入四、基本使用五、事件监听六、播放 HLS 流七、更多功能总结在 v

JS纯前端实现浏览器语音播报、朗读功能的完整代码

《JS纯前端实现浏览器语音播报、朗读功能的完整代码》在现代互联网的发展中,语音技术正逐渐成为改变用户体验的重要一环,下面:本文主要介绍JS纯前端实现浏览器语音播报、朗读功能的相关资料,文中通过代码... 目录一、朗读单条文本:① 语音自选参数,按钮控制语音:② 效果图:二、朗读多条文本:① 语音有默认值:②

vue监听属性watch的用法及使用场景详解

《vue监听属性watch的用法及使用场景详解》watch是vue中常用的监听器,它主要用于侦听数据的变化,在数据发生变化的时候执行一些操作,:本文主要介绍vue监听属性watch的用法及使用场景... 目录1. 监听属性 watch2. 常规用法3. 监听对象和route变化4. 使用场景附Watch 的

前端导出Excel文件出现乱码或文件损坏问题的解决办法

《前端导出Excel文件出现乱码或文件损坏问题的解决办法》在现代网页应用程序中,前端有时需要与后端进行数据交互,包括下载文件,:本文主要介绍前端导出Excel文件出现乱码或文件损坏问题的解决办法,... 目录1. 检查后端返回的数据格式2. 前端正确处理二进制数据方案 1:直接下载(推荐)方案 2:手动构造

Vue实现路由守卫的示例代码

《Vue实现路由守卫的示例代码》Vue路由守卫是控制页面导航的钩子函数,主要用于鉴权、数据预加载等场景,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着... 目录一、概念二、类型三、实战一、概念路由守卫(Navigation Guards)本质上就是 在路

uni-app小程序项目中实现前端图片压缩实现方式(附详细代码)

《uni-app小程序项目中实现前端图片压缩实现方式(附详细代码)》在uni-app开发中,文件上传和图片处理是很常见的需求,但也经常会遇到各种问题,下面:本文主要介绍uni-app小程序项目中实... 目录方式一:使用<canvas>实现图片压缩(推荐,兼容性好)示例代码(小程序平台):方式二:使用uni