4、条形分区统计
<div ref="chartsVal1" class="chartsline-div"></div>
const chartsVal1 = ref(null);
const chartsVal1Title = ref('运行时间统计');drewCharts2(chartsVal1, chartsVal1Title.value);function drewCharts2(id, title) {const mapChart = echarts.init(id.value);window.onresize = mapChart.resize; //如果容器变大小,自适应从新构图// const lineData: number[][] = Array.from({ length: 4 }, () => Array(25).fill(0));const grid = {left: 100,right: 100,top: 50,bottom: 30};const series: echarts.BarSeriesOption[] = ['运行时间','待机时间','报警时间','离线时间',].map((name, sid) => {return {name,type: 'bar',stack: 'total',barWidth: '20%',label: {show: true,// formatter: (params: any) => Math.round(params.value * 1000) / 10 + '%'},data: lineData[sid].map((d, did) =>d),};});const option = {legend: {selectedMode: false},grid,color: ['rgb(21,184,120)', 'rgb(255,207,41)', 'rgb(252,85,62)', 'rgb(155,201,238)',],yAxis: {name: '时间(min)',type: 'value'},xAxis: {name: '日期时间',type: 'category',data: categoryTime.value},series,tooltip: {trigger: "item",// axisPointer: {// type: "shadow"// },// formatter: function (params) {// let name = params.name == 1 ? "设备报警" : "系统报警";// return params.marker + name + ":" + params.value;// }},};// Generate data// let category = this.motorStatusCategory;// let lineData = data;// let option = this.getOptions1(id, title);// option// let option = {// title: {// text: title,// // subtext: 'Example in MetricsGraphics.js',// left: 'center'// },// tooltip: {// trigger: "axis",// axisPointer: {// type: "shadow"// }// },// grid: {// left: 50,// right: 20,// bottom: 30,// top: 10// },// legend: {// data: ["line"],// textStyle: {// color: "#ccc"// }// },// xAxis: {// minInterval: 1,// maxInterval: 2,// data: category,// axisLine: {// lineStyle: {// color: "#ccc"// }// }// },// yAxis: {// max: 100,// min: minVal,// splitLine: { show: false },// axisLine: {// lineStyle: {// color: "#ccc"// }// }// },// series: [// {// name: title,// type: "line",// smooth: true,// showAllSymbol: true,// symbol: "emptyCircle",// symbolSize: 15,// data: lineData// },// ]// };mapChart.setOption(option); //生成图表
};
3、饼图(展示百分比+分数)
<el-col class="charts-percentage-col" :span="12"><div ref="charts1" class="chartspie-div"></div><div class="charts-percentage-div">{{ chartsData.overduePercentage }}</div>
</el-col>
function getChartsData() {let data = {total: 99,overdue: 33,soon: 33,normal: 33,};data.overdueProportion = overdueFraction(data.overdue, data.total);data.soonProportion = overdueFraction(data.soon, data.total);data.normalProportion = overdueFraction(data.normal, data.total);data.overduePercentage = overduePercentage(data.overdue, data.total);data.soonPercentage = overduePercentage(data.soon, data.total);data.normalPercentage = overduePercentage(data.normal, data.total);console.log(data);chartsData.value = data;
};function overduePercentage(num, total) {if (!total || total === 0) {return '0.00%';}const percentage = (num / total) * 100;return percentage.toFixed(2) + '%';
};function overdueFraction(num, total) {function gcd(a, b) {return b ? gcd(b, a % b) : a;};if (!total || total === 0) {return '0/0';}const commonDivisor = gcd(Math.abs(num), Math.abs(total));// return (num /commonDivisor) + '/' (total / commonDivisor);// return num / total;return (num / commonDivisor) + ' / ' + (total / commonDivisor);};function initCharts() {drewCharts1(charts1, charts1Title.value);drewCharts1(charts2, charts2Title.value);drewCharts1(charts3, charts3Title.value);
};function drewCharts1(id, title) {const mapChart = echarts.init(id.value);window.onresize = mapChart.resize; //如果容器变大小,自适应从新构图const options = {grid: {// left: 140,// right: 120,// bottom: -30,// top: 0},angleAxis: {startAngle: 90, // 开始位置clockwise: true,// 是否顺时针// max: 100,// 坐标轴最大值100axisLine: {show: false // 不显示坐标轴},splitNumber: 1,axisTick: {show: false,//是否展示刻度},axisTick: {show: false,//是否展示刻度// length: 2,// 刻度长度// splitNumber: 20},},radiusAxis: {type: 'category',axisLine: {show: false},axisTick: {show: false,//是否展示刻度length: 2,// 刻度长度splitNumber: 20},axisLabel: {inside: false}},polar: {center: ['50%', '60%'],radius: ['45%', '100%'],},series: [{type: 'bar',data: [{value: 20,itemStyle: {// color: '#f5a623',borderRadius: ['50%', '50%', '50%', '50%'],}},],coordinateSystem: 'polar',name: title,stack: 'a',barMaxWidth: '27%', // 柱状图的粗细},{type: 'bar',data: [{value: 100 - 20,itemStyle: {color: '#eceef0',borderRadius: ['50%', '50%', '50%', '50%'],}},],coordinateSystem: 'polar',name: '其他',stack: 'a',barMaxWidth: '27%', // 柱状图的粗细}],tooltip: {trigger: "item",// formatter: "{a} <br/>{b}: {c} ({d}%)"},};switch (id) {case charts1:options.series[0].data[0].value = chartsData.value.overdue;options.series[1].data[0].value = chartsData.value.total - chartsData.value.overdue;options.series[0].data[0].itemStyle.color = '#F2637B';break;case charts2:options.series[0].data[0].value = chartsData.value.soon;options.series[1].data[0].value = chartsData.value.total - chartsData.value.soon;options.series[0].data[0].itemStyle.color = '#36CBCB';break;case charts3:options.series[0].data[0].value = chartsData.value.normal;options.series[1].data[0].value = chartsData.value.total - chartsData.value.normal;options.series[0].data[0].itemStyle.color = '#3AA1FF';break;default:break;}mapChart.setOption(options); //生成图表
};
2、折线图(带平均值)
getSeries1(id, title) {const serie = {name: title,type: "line",smooth: true,showAllSymbol: true,symbol: "emptyCircle",symbolSize: 15,// data: lineData};const series = [];if (id == 'charts2') {for (let i = 0; i < 3; i++) {let serie = {name: title,type: "line",smooth: true,showAllSymbol: true,symbol: "emptyCircle",symbolSize: 15,// data: lineData};series.push(serie);}series[0].data = this.chartsData.map(item => item.disturbancePercentageCurrent);series[0].name = '当前';series[1].data = this.chartsData.map(item => item.disturbancePercentageMax);series[1].name = '最大';series[2].data = this.chartsData.map(item => item.disturbancePercentageMin);series[2].name = '最小';} else {if (id == 'charts3') {serie.data = this.chartsData.map(item => item.overheatPercentage);// series[0] = serie;} else if (id == 'charts1') {serie.data = this.chartsData.map(item => item.torquePercentage);// series[0] = serie;} else if (id == 'chartsVal1') {serie.data = this.chartsData.map(item => item.torqueMax);} else if (id == 'chartsVal2') {serie.data = this.chartsData.map(item => item.disturbanceTorqueMax);} else if (id == 'chartsVal3') {serie.data = this.chartsData.map(item => item.pulseDifferenceMax);}serie.markPoint = {data: [{ type: 'max', name: 'Max' },{ type: 'min', name: 'Min' }]};serie.markLine = {data: [{ type: 'average', name: 'Avg' }]};series[0] = serie;}return series;},getOptions1(id, title) {const minVal = id == 'charts2' ? -100 : 0;let category = this.motorStatusCategory;const options = {title: {text: title,// subtext: 'Example in MetricsGraphics.js',left: 'center',},tooltip: {trigger: "axis",axisPointer: {type: "shadow"},formatter: function (params) {let text = params[0].axisValueLabel + "</br>";for (var i = 0; i < params.length; i++) {text += params[i].marker + params[i].seriesName + ":" + parseFloat(params[i].value).toFixed(2);if (params[0].seriesName == '扭矩百分比' || `${id}` == '当前' || `${id}` == '过热率百分比') {text += "%</br>";} else {text += "</br>";}}return text;}},grid: {left: 50,right: 60,bottom: 30,top: '20%'},legend: {data: ["line"],textStyle: {color: "#ccc"}},xAxis: {name: '日期\n时间',minInterval: 1,maxInterval: 2,data: category,axisLine: {lineStyle: {color: "#ccc"}}},yAxis: {name: '%',// max: 100,min: minVal,splitLine: { show: false },axisLine: {lineStyle: {color: "#ccc"}}},// series: [// {// name: title,// type: "line",// smooth: true,// showAllSymbol: true,// symbol: "emptyCircle",// symbolSize: 15,// data: lineData// },// ]};if (id == 'charts2') {options.yAxis.max = 100;}const series = this.getSeries1(id, title);options.series = series;return options;},
1、地图展示
//中国地图china_map() {let mapChart = this.$echarts.init(document.getElementById("china-map")); //图表初始化,china-map是绑定的元素window.onresize = mapChart.resize; //如果容器变大小,自适应从新构图let series = [];series.push({type: "scatter",coordinateSystem: "geo",symbol: "pin",legendHoverLink: true,symbolSize: [60, 60],// 这里渲染标志里的内容以及样式label: {show: true,formatter(value) {return value.data.value[2].cityName;},color: "#fff"},// 标志的样式itemStyle: {normal: {color: "rgba(255,0,0,.7)",shadowBlur: 2,shadowColor: "D8BC37"}},// 数据格式,其中name,value是必要的,value的前两个值是数据点的经纬度,其他的数据格式可以自定义// 至于如何展示,完全是靠上面的formatter来自己定义的// data: [// // { name: "西藏", value: [91.23, 29.5, 2333] },// // { name: "黑龙江", value: [128.03, 47.01, 1007] },// // { name: "新疆", value: [86.9023, 41.148, 507] },// // { name: "内蒙古", value: [110.5977, 41.3408, 407] },// // { name: "广西", value: [108.7813, 23.6426, 777] },// // { name: "陕西", value: [108.5996, 33.7396, 907] },// // { name: "四川", value: [102.9199, 30.1904, 207] },// { name: "苏州市", value: [120.619585, 31.299379, { city: "苏州市" }] },// { name: "南京市", value: [118.767413, 32.041544, { city: "南京市" }] }// ],data: this.mapData,showEffectOn: "render",rippleEffect: {brushType: "stroke"},hoverAnimation: true,zlevel: 1});// {// type: "effectScatter",// coordinateSystem: "geo",// effectType: "ripple",// showEffectOn: "render",// rippleEffect: {// period: 10,// scale: 10,// brushType: "fill",// },// hoverAnimation: true,// itemStyle: {// normal: {// color: "rgba(255, 235, 59, .7)",// shadowBlur: 10,// shadowColor: "#333",// },// },// zlevel: 1,// data: [// { name: "西藏", value: [91.23, 29.5, 2333] },// { name: "黑龙江", value: [128.03, 47.01, 1007] },// ],// },let option = {// 背景颜色// 提示浮窗样式tooltip: {show: true,trigger: "item",alwaysShowContent: false,backgroundColor: "#0C121C",borderColor: "#293171",hideDelay: 100,triggerOn: "mousemove",enterable: true,textStyle: {color: "#DADADA",fontSize: "12",width: 20,height: 30,overflow: "break"},showDelay: 100,formatter(params) {// return `地区:${params.name}`;//地区:${params.name}</br>装置:${params.value[2].city}return `名称:${params.value[2].name}</br>所在城市:${params.value[2].cityName}</br>`;}},// 地图配置geo: {map: "china",label: {// 通常状态下的样式normal: {show: true,textStyle: {color: "#fff"}},// 鼠标放上去的样式emphasis: {textStyle: {color: "#fff"}}},// 地图区域的样式设置itemStyle: {normal: {borderColor: "#293171", //地图边框颜色borderWidth: 2, //地图边框粗细areaColor: "#0A0F33" //地图背景色},//省份地图阴影emphasis: {areaColor: null,shadowOffsetX: 0,shadowOffsetY: 0,shadowBlur: 20,borderWidth: 1,shadowColor: "#fff"}}},series: series};mapChart.setOption(option); //生成图表//this.chinaMapHidden(mapChart);},