echarts多条折线图

news/2025/1/13 10:50:47/

在这里插入图片描述

代码

<template><div><!-- 折线图 --><div id="average-score1" class="risk-percent" /></div>
</template><script>
import * as echarts from "echarts";export default {name: "StrategicRisk",components: {},// props: ["id"],data() {return {// define optionsoptions: [],};},mounted() {this.$nextTick(() => {this.setRiskPercent2();});},methods: {lineUp(x) {if (x) {return 11 - x;} else {return x;}},setRiskPercent2() {let Ydata1 = [1, 4, 4].map(this.lineUp);let Ydata2 = [2, 2, 3].map(this.lineUp);let Ydata3 = [3, 9, 8].map(this.lineUp);let Ydata4 = [4, 3, 5].map(this.lineUp);let Ydata5 = [5, 1, null].map(this.lineUp);let Ydata6 = [6, 10, 10].map(this.lineUp);let Ydata7 = [7, 5, 1].map(this.lineUp);let Ydata8 = [8, null, null].map(this.lineUp);let Ydata9 = [9, 8, 6].map(this.lineUp);let Ydata10 = [10, 6, 7].map(this.lineUp);let Ydata11 = [null, 7, 2].map(this.lineUp);let Ydata12 = [null, null, 9].map(this.lineUp);let Ydata13 = [null, null, 3].map(this.lineUp);//排名前三let Ydata14 = [null, null, 4].map(this.lineUp);//排名前三let Ydata15 = [null, null, 5].map(this.lineUp);//排名前三let Ydata16 = [null, null, 9].map(this.lineUp);//本年新增//预设数据格式let obj = {会计基础: {0: [1, 4, 4],1: [100, 70, 70],3: "topFive",},"决策管理": {0: [2, 2, 3],1: [90, 90, 80],3: "topFive",},合同管理: {0: [3, 9, 8],1: [80, 20, 30],3: false,},公司治理: {0: [4, 3, 5],1: [70, 80, 60],3: "topFive",},仓库管理: {0: [5, 1, null],1: [60, 100, null],3: false,},往来款管理: {0: [6, 10, 10],1: [50, 10, 10],3: false,},资金管理: {0: [7, 5, 1],1: [40, 60, 100],3: false,},销售管理: {0: [8, null, null],1: [30, null, null],3: false,},采购管理: {0: [9, 8, 6],1: [20, 30, 50],3: false,},制度建设: {0: [10, 6, 7],1: [10, 50, 40],3: false,},其他: {0: [null, 7, 2],1: [null, 40, 90],3: false,},往来款管理1: {0: [null, null, 9],1: [null, null, 20],3: "new",},};let dataX = ["2021", "2022", "2023"];// let Ydata1 = [100, 70, 70];// let Ydata2 = [90, 90, 80];// let Ydata3 = [80, 20, 30];// let Ydata4 = [70, 80, 60];// let Ydata5 = [60, 100, null];// let Ydata6 = [50, 10, 10];// let Ydata7 = [40, 60, 100];// let Ydata8 = [30, null, null];// let Ydata9 = [20, 30, 50];// let Ydata10 = [10, 50, 40];// let Ydata11 = [null, 40, 90];// let Ydata12 = [null, null, 20];// let Ydata13 = [null, null, 3];// let Ydata14 = [null, null, 4];// let Ydata15 = [null, null, 5];// let Ydata16 = [null, null, 9];var elementById = document.getElementById("average-score1");var myChart = echarts.init(elementById);myChart.setOption({// title: {//   text: "Stacked Line",// },tooltip: {// trigger: "axis",trigger: "item",formatter: (params, ticket, callback) => {// console.log("params", params, obj[params.seriesName][1]);let str = ``;let index = dataX.indexOf(params.name);// str = obj[params.seriesName][1][index];str =params.seriesName +`风险<br/>` +params.name +`年排名第` +obj[params.seriesName][0][index] +`<br/>` +`共上报` +obj[params.seriesName][1][index] +`项<br/>`;return str;},},legend: {data: ["会计基础","决策管理","合同管理","公司治理","仓库管理","往来款管理","资金管理","销售管理","采购管理","制度建设","其他","往来款管理1",],orient: "vertical",right: "7%",align: "left",top: "middle",icon: "circle",itemWidth: 7,itemGap: 10,},grid: {left: "4%",right: "30%",bottom: "4%",top: "8%",containLabel: true,},// toolbox: {//   feature: {//     saveAsImage: {},//   },// },xAxis: {type: "category",boundaryGap: false,data: dataX,splitLine: {show: true,},axisLine: {show: true,// lineStyle: {//   type: "dotted",// },},},yAxis: [{type: "value",axisTick: {show: false,},axisLine: {show: false,},lineStyle: {opacity: 0.2,type: "dashed",color: "#748ca4",},// data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],interval: 1, // 步长min: 1, // 起始max: 10, // 终止axisLabel: {fontSize: 14,fontFamily: "Alibaba-PuHuiTi-R, Alibaba-PuHuiTi",formatter: (value) => {console.log("value1", value);let str = "";if (value == 1) {str = "第十名";} else if (value == 2) {str = "第九名";} else if (value == 3) {str = "第八名";} else if (value == 4) {str = "第七名";} else if (value == 5) {str = "第六名";} else if (value == 6) {str = "第五名";} else if (value == 7) {str = "第四名";} else if (value == 8) {str = "第三名";} else if (value == 9) {str = "第二名";} else if (value == 10) {str = "第一名";}return str;},},},],series: [// ----------------标签{name: "往来款管理12",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小lineStyle: {color: "transparent",},// label: {//   normal: {//     show: true,//     position: "right",//   },// },label: {offset: [5, 1],color: "#fff",show: true,position: "right",distance: 7.5,rotate: 0,fontSize: 15,verticalAlign: "middle",backgroundColor: "#2c95ff",borderRadius: [9, 9, 9, 9],width: 64,height: 26,align: "left",lineHeight: 17,padding: [2, 10, 2, 10],formatter: (value) => {console.log("value", value);let str = "连续3期排名前五";return str;},},data: Ydata13,},{name: "往来款管理13",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小lineStyle: {color: "transparent",},// label: {//   normal: {//     show: true,//     position: "right",//   },// },label: {offset: [5, 1],color: "#fff",show: true,position: "right",distance: 7.5,rotate: 0,fontSize: 15,verticalAlign: "middle",backgroundColor: "#2c95ff",borderRadius: [9, 9, 9, 9],width: 64,height: 26,align: "left",lineHeight: 17,padding: [2, 10, 2, 10],formatter: (value) => {console.log("value", value);let str = "连续3期排名前五";return str;},},data: Ydata14,},{name: "往来款管理14",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小lineStyle: {color: "transparent",},// label: {//   normal: {//     show: true,//     position: "right",//   },// },endLabel: {show: true,distance: 8.5,borderDashOffset: 20,},label: {offset: [5, 1],color: "#fff",show: true,position: "right",distance: 7.5,rotate: 0,fontSize: 15,verticalAlign: "middle",backgroundColor: "#2c95ff",borderRadius: [9, 9, 9, 9],width: 64,height: 26,align: "left",lineHeight: 17,padding: [2, 10, 2, 10],formatter: (value) => {console.log("value", value);let str = "连续3期排名前五";return str;},},data: Ydata15,},{name: "往来款管理15",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: "transparent",},},lineStyle: {color: "#008080",// color: "transparent"},// label: {//   normal: {//     show: true,//     position: "right",//   },// },label: {offset: [5, 1],color: "#fff",show: true,position: "right",distance: 7.5,rotate: 0,fontSize: 15,verticalAlign: "middle",backgroundColor: "#2c95ff",borderRadius: [9, 9, 9, 9],width: 64,height: 26,align: "left",lineHeight: 17,padding: [2, 10, 2, 10],formatter: (value) => {console.log("value", value);let str = "2023年新增";return str;},},data: Ydata16,},// ------------折线{name: "会计基础",type: "line",// yAxisIndex: 1, //使用的 y 轴的 index,在单个图表实例中存在多个 y轴的时候有用smooth: false, //平滑曲线显示symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: "#317ef3",// borderColor: "rgba(64, 162, 219, 0.5)", //圆点透明 边框// borderWidth: 2,},},lineStyle: {color: "#317ef3", //1},// data: [1, 4, 4],data: Ydata1,},{name: "决策管理",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: "#8dcfa3",},},lineStyle: {color: "#8dcfa3", //1},data: Ydata2,},{name: "合同管理",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: "#9085f4",},},lineStyle: {color: "#9085f4", //},data: Ydata3,},{name: "公司治理",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: "#7fcdde",},},lineStyle: {color: "#7fcdde", //},data: Ydata4,},{name: "仓库管理",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: "#dd773b",},},lineStyle: {color: "#dd773b", //},data: Ydata5,},//{name: "往来款管理",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: "#f0aebc",},},lineStyle: {color: "#f0aebc",},data: Ydata6,},{name: "资金管理",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: "#418b9b",},},lineStyle: {color: "#418b9b",},data: Ydata7,},// 销售管理{name: "销售管理",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: "#e5bb45",},},lineStyle: {color: "#e5bb45",},data: Ydata8,},{name: "采购管理",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: "#b256e7",},},lineStyle: {color: "#b256e7",},data: Ydata9,},{name: "制度建设",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: "#abc0fb",},},lineStyle: {color: "#abc0fb",},data: Ydata10,},{name: "其他",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: "#5aa52c",},},lineStyle: {color: "#5aa52c",},data: Ydata11,},{name: "往来款管理1",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: "#008080",},},lineStyle: {color: "#008080",},data: Ydata12,},],});window.addEventListener("resize", function () {//自适应屏幕大小myChart.resize();});},},
};
</script>
<style scoped>
.parent {
}
.risk-percent {width: 100%;height: 300px;flex-shrink: 1;flex-grow: 1;margin-top: 30px;
}
</style>

代码优化

//代码优化
<template><div><!-- 折线图 --><div id="average-score1" class="risk-percent" /></div>
</template><script>
import * as echarts from "echarts";export default {name: "StrategicRisk",components: {},// props: ["id"],data() {return {// define optionsoptions: [],};},mounted() {// this.$nextTick(() => {//   this.setRiskPercent2(val);// });},methods: {lineUp(x) {if (x == "null") {x = null;}if (x) {return 11 - x;} else {return x;}},setRiskPercent2(val) {console.log("val12121setRiskPercent2", val);//let Ydata1 = [1, 4, 4].map(this.lineUp);// let Ydata2 = [2, 2, 3].map(this.lineUp);//let Ydata3 = [3, 9, 8].map(this.lineUp);//let Ydata4 = [4, 3, 5].map(this.lineUp);//let Ydata5 = [5, 1, null].map(this.lineUp);//let Ydata6 = [6, 10, 10].map(this.lineUp);//let Ydata7 = [7, 5, 1].map(this.lineUp);//let Ydata8 = [8, null, null].map(this.lineUp);//let Ydata9 = [9, 8, 6].map(this.lineUp);//let Ydata10 = [10, 6, 7].map(this.lineUp);//let Ydata11 = [null, 7, 2].map(this.lineUp);//let Ydata12 = [null, null, 9].map(this.lineUp);//let Ydata13 = [null, null, 3].map(this.lineUp);//let Ydata14 = [null, null, 4].map(this.lineUp);//let Ydata15 = [null, null, 5].map(this.lineUp);//let Ydata16 = [null, null, 9].map(this.lineUp);let obj1111 = {会计基础: {0: [1, 4, 4],//排名1: [100, 70, 70],//数量3: "topFive",},"决策管理": {0: [2, 2, 3],1: [90, 90, 80],3: "topFive",},合同管理: {0: [3, 9, 8],1: [80, 20, 30],3: false,},公司治理: {0: [4, 3, 5],1: [70, 80, 60],3: "topFive",},仓库管理: {0: [5, 1, null],1: [60, 100, null],3: false,},往来款管理: {0: [6, 10, 10],1: [50, 10, 10],3: false,},资金管理: {0: [7, 5, 1],1: [40, 60, 100],3: false,},销售管理: {0: [8, null, null],1: [30, null, null],3: false,},采购管理: {0: [9, 8, 6],1: [20, 30, 50],3: false,},制度建设: {0: [10, 6, 7],1: [10, 50, 40],3: false,},其他: {0: [null, 7, 2],1: [null, 40, 90],3: false,},往来款管理1: {0: [null, null, 9],1: [null, null, 20],3: "new",},};let dataX = ["2020", "2021", "2022"];let legendData = Object.keys(obj1111);let colorList = ["#317ef3","#8dcfa3","#9085f4","#7fcdde","#dd773b","#f0aebc","#418b9b","#e5bb45","#b256e7","#abc0fb","#5aa52c","#008080","#3171f1","#81c1a1","#9181f1","#71c1d1","#d17131","#f1a1b1","#418191","#e1b141","#b151e1","#a1c1f1","#51a121","#018181",];let i = 0;let seriesList = [];let seriesList2 = [];for (let key in obj1111) {// obj[key][0].map(this.lineUp)console.log("key", key, obj1111[key]);console.log("obj[key]", obj1111[key], obj1111[key][3], i);//代表一条线let seriesObj = {name: key,type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小itemStyle: {normal: {color: colorList[i],},},lineStyle: {color: colorList[i], //1},data: obj1111[key][0].map(this.lineUp),};seriesList.push(seriesObj);if (obj1111[key][3]) {//代表一个标签let seriesObj2 = {name: key + "0",type: "line",symbol: "circle", //标记的图形为实心圆symbolSize: 6, //标记的大小lineStyle: {color: "transparent",},label: {offset: [5, 1],color: "#fff",show: true,position: "right",distance: 7.5,rotate: 0,fontSize: 15,verticalAlign: "middle",backgroundColor: "#2c95ff",borderRadius: [9, 9, 9, 9],width: 64,height: 26,align: "left",lineHeight: 17,padding: [2, 10, 2, 10],formatter: (value) => {console.log("value", value);let str = obj1111[key][3];return str;},},data: [null, null, obj1111[key][0][2]].map(this.lineUp),};seriesList2.push(seriesObj2);}i++;}console.log("seriesList112121212", seriesList, seriesList2, legendData);var elementById = document.getElementById("average-score1");var myChart = echarts.init(elementById);myChart.setOption({// title: {//   text: "Stacked Line",// },tooltip: {// trigger: "axis",trigger: "item",formatter: (params, ticket, callback) => {// console.log("params", params, obj[params.seriesName][1]);let str = ``;let index = dataX.indexOf(params.name);str =params.seriesName +`风险<br/>` +params.name +`年排名第` +obj1111[params.seriesName][0][index] +`<br/>` +`共上报` +obj1111[params.seriesName][1][index] +`项<br/>`;return str;},},color: colorList,legend: {data: legendData,orient: "vertical",right: "2%",align: "left",top: "middle",icon: "circle",itemWidth: 7,itemGap: 10,},grid: {left: "4%",right: "35%",bottom: "4%",top: "8%",containLabel: true,},xAxis: {type: "category",boundaryGap: false,data: dataX,splitLine: {show: true,},axisLine: {show: true,// lineStyle: {//   type: "dotted",// },},},yAxis: [{type: "value",axisTick: {show: false,},axisLine: {show: false,},lineStyle: {opacity: 0.2,type: "dashed",color: "#748ca4",},// data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],interval: 1, // 步长min: 1, // 起始max: 10, // 终止axisLabel: {fontSize: 14,fontFamily: "Alibaba-PuHuiTi-R, Alibaba-PuHuiTi",formatter: (value) => {console.log("value1", value);let str = "";if (value == 1) {str = "第十名";} else if (value == 2) {str = "第九名";} else if (value == 3) {str = "第八名";} else if (value == 4) {str = "第七名";} else if (value == 5) {str = "第六名";} else if (value == 6) {str = "第五名";} else if (value == 7) {str = "第四名";} else if (value == 8) {str = "第三名";} else if (value == 9) {str = "第二名";} else if (value == 10) {str = "第一名";}return str;},},},],series: [// ----------------...seriesList2,//带标签的...seriesList,//折线],});},},
};
</script>
<style scoped>
.parent {
}
.risk-percent {width: 100%;height: 300px;flex-shrink: 1;flex-grow: 1;margin-top: 30px;
}
</style>

http://www.ppmy.cn/news/1033635.html

相关文章

Visual Studio 与QT ui文件

对.ui文件鼠标右键&#xff0c;然后单击 Open with…在弹出的窗口中&#xff0c;选中左侧的 Qt Designer&#xff0c;然后单击右侧的 Add 按钮&#xff0c;随后会弹出一个窗口&#xff0c;在 Program: 输入框中输入 Qt Designer 的路径&#xff0c;最后单击 OK找到 Qt Designer…

字节春招JAVA后端开发面试总结

春招的字节二面面经,岗位是后端开发。 一个编程语言都没问,都是问网络+项目+mysql+redis。 问题记录 使用消息中间件降低消息持久化的压力是怎么做的,为什么可以降低? 在突发大量消息的情况下可以做到流量削峰,在消费者消费能力达不到生产者产生消息的速度时也能够正常…

分割字符串的最大得分

题目&#xff1a; 给你一个由若干 0 和 1 组成的字符串 s &#xff0c;请你计算并返回将该字符串分割成两个 非空 子字符串&#xff08;即 左 子字符串和 右 子字符串&#xff09;所能获得的最大得分。 「分割字符串的得分」为 左 子字符串中 0 的数量加上 右 子字符串中 1 的…

Linux的ln命令

ln是link的缩写,在Linux中 ln 命令的功能是为某一个文件在另外一个位置建立一个同步的链接&#xff0c;当我们需要在不同的目录&#xff0c;用到相同的文件时&#xff0c;我们不需要在每一个需要的目录下都放一个必须相同的文件&#xff0c;我们只要在某个固定的目录&#xff0…

全面拥抱AI时刻来临?基于AI技术助力养猪产仔是否可行?

这两天看到一篇论文&#xff0c;蛮有意思的&#xff0c;技术层面倒没有什么新颖的点&#xff0c;主要是落地应用场景比较贴近现实&#xff0c;文章主要就是应用yolov5来开发构建了一套母猪产仔智能化检测预警模型&#xff0c;从而来降低大型养殖场中人工成本。一起来简单看下吧…

理解持续测试,才算理解DevOps

软件产品的成功与否&#xff0c;在很大程度上取决于对市场需求的及时把控&#xff0c;采用DevOps可以加快产品交付速度&#xff0c;改善用户体验&#xff0c;从而有助于保持领先于竞争对手的优势。 作为敏捷开发方法论的一种扩展&#xff0c;DevOps强调开发、测试和运维不同团队…

TypeScript教程(一)简介与安装

一、简介 TypeScript 是 JavaScript 的一个超集&#xff0c;扩展了JavaScript的语法&#xff0c;因此现有的JavaScript可与TypeScript一起工作无需修改&#xff0c;支持 ECMAScript 6 标准&#xff08;ES6 教程&#xff09;。 语言特性&#xff1a; 1.类型批注和编译时类型检…

3.文件目录

第四章 文件管理 3.文件目录 ​   对于D盘这个根目录来说它对应的目录文件就是图中的样子&#xff0c;其实就是用一个所谓的目录表来表示这个目录下面存放了哪些东西。在D盘中的每一个文件&#xff0c;每一个文件夹都会对应这个目录表中的一个表项&#xff0c;所以其实这些一…