行业知识
vue管理系统封装echarts
2026-11-18 18:31:17
来源:互联网转载
创建个echartsComponent文件
import * as echarts from "echarts";import { mapGetters } from 'vuex'const get_uuid = () => { var s = []; var hexDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; for (var i = 0; i { this.$nextTick(() => { if(!this.hasImgBase64) { // 首页 需要采用svg渲染,比canvans清晰度高 this.myChart = echarts.init(dom, null, {renderer: 'svg'}) } else { this.myChart = echarts.init(dom) } if(this.myChart) { this.myChart.setOption(this.option, true) window.addEventListener('resize', () => { this.debounce(this.chartResize, 300) }) } }) }, 300) } }, // uuid2是为导出生成的固定宽高的折线图,无需考虑自适应 drawChartImg() { var dom2 = document.getElementById(this.uuid2) if(dom2) { dom2.removeAttribute('_echarts_instance_'); if (this.myImgChart != null && this.myImgChart != "" && this.myImgChart != undefined) {this.myImgChart.dispose();//销毁实例,实例销毁后无法再被使用 } setTimeout(() => { this.$nextTick(() => { this.myImgChart = echarts.init(dom2) if(this.myImgChart) { const imgOption = { ...this.option, animation: false } this.myImgChart.setOption(imgOption, true) this.imagesBase64 = this.myImgChart.getDataURL() this.$emit('getChartImg', this.imagesBase64) } }) }, 300) } }, // 左侧菜单缩放,切换其他页面,激活页面时activated调用该函数echarts自适应调用 // 需要图表自适应都可调用 sidebarChange(time) { this.debounce(this.chartResize, time ?? 300) }, }};.chart { width:100%; height:100%; position:relative; &-show { position: absolute; width: 100%; height: 100%; > p{ width: 100%; height: 100%; } }}.img-chart { overflow: hidden; &-show { background-color: #fff; z-index: 2; } &-export { position: absolute; width: 100%; height: 100%; z-index: 1; > p{ width: 1200px; height: 800px; } }} 在其他页面传入data即可调用
{option = val ? val : [ { value: 0, name: '0~3公里' }, { value: 0, name: '3~6公里' }, { value: 0, name: '6~10公里' }, { value: 0, name: '10~15公里' }, { value: 0, name: '15~25公里' }, { value: 0, name: '25~35公里' }, { value: 0, name: '大于等于35公里' } ] return { tooltip: { show:true, trigger: 'item', confine: true, borderWidth: 0, formatter: function(params){ let tip = ''; if(params.seriesIndex === 0){ tip = params.marker + params.name + ":" + params.percent + '%' }else if(params.seriesIndex === 1){ tip = '' } return tip ; } }, legend: { textStyle: { padding:[fontSize(-8),0,0,0], height: fontSize(36), width: fontSize(64), backgroundColor: 'transparent', rich: { name: { fontSize: fontSize(12), padding:[fontSize(4),0,0,0], }, num: { fontSize: fontSize(16), fontWeight: 600, color: '#333', padding:[fontSize(-4),0,0,fontSize(-20)], } }, }, top: '50%', left: 'center', icon: 'rect', itemHeight: fontSize(10), itemWidth: fontSize(10), formatter: function (name) { const item = data.find(item => item.name === name) const num = item.value return [ `{num| ${num} %}`, // 这里注意返回数组类型,内为对象,对象必须包裹成字符串,c为当前文字标识,| 后为你想显示的值 `{name| ${name}}`, ].join('\n') // 换行 } }, graphic: { elements: [ { type: 'image', style: { image: require("../images/home_distance.png"), // image: require("@/views/vehicleMonitor/home-page/assets/images/home_distance.png"), width: fontSize(38), height: fontSize(34), }, left: '44.5%', top: '24%' } ] }, color:['#165DFF', '#57E4F3', '#FF724B','#F6D449', '#FEAA38','#7F76FF','#E784FF'], series: [ { type: 'pie', zlevel: 2, //层级 radius: ['24%', '37%'], avoidLabelOverlap: false, center: ['50%', '30%'], itemStyle: { borderRadius: fontSize(8), normal: { // 饼状图阴影,值越大阴影亮度越高 shadowBlur: fontSize(6), shadowColor: 'rgba(227, 228, 238, 0.1)' } }, label: { show: false, position: 'center' }, data: data, }, // 外环 { type: 'pie', // radius: ['23%', '40%'], radius: ['21%', '40%'], center: ['50%', '30%'], itemStyle: { normal: { color: 'rgba(0,0,0,.06)', label: { show: false }, labelLine: { show: false } }, }, hoverAnimation: false, data: [100], } ] }} ()()
上一篇:中山商品房网签备案情况怎么查询
下一篇:惠普应用商店,科技应用的探索乐园