把后端返回的复杂数据转换为ECharts需求用的数据

news/2024/11/8 9:47:29/

把后端返回的复杂数据转换为ECharts需求用的数据

数据:

0:{category: "来喜", ddate: "2021-08-09", price: 3000}
1: {category: "来喜", ddate: "2021-08-17", price: 5}
2: {category: "五洲", ddate: "2021-08-17", price: 5}
3: {category: "恒升", ddate: "2021-08-17", price: 5}
4: {category: "东源", ddate: "2021-08-17", price: 5}
5: {category: "腾远", ddate: "2021-08-17", price: 5}
6: {category: "鑫义", ddate: "2021-08-17", price: 5}
7: {category: "北海", ddate: "2021-08-17", price: 5}
8: {category: "东风镁业", ddate: "2021-08-17", price: 5}
9: {category: "泰和", ddate: "2021-08-17", price: 5}
10: {category: "江泰", ddate: "2021-08-17", price: 5}
11: {category: "祥荣", ddate: "2021-08-17", price: 5}
12: {category: "江泰总公司", ddate: "2021-08-17", price: 1}
13: {category: "同得利", ddate: "2021-08-17", price: 1}
14: {category: "鑫泰", ddate: "2021-08-17", price: 1}
15: {category: "君正", ddate: "2021-08-17", price: 1}
16: {category: "鄂绒", ddate: "2021-08-17", price: 1}

实现过程:

<template><div class="pricePlatT_firstOilChart"><SubTtile :title="title"></SubTtile><!-- 1#油价格折线图 --><div id="pricePlatT_firstOilChart" :ref="id"></div></div>
</template><script>
import {reqDlSupplyPriceCompare} from '@api/PricePlatT'
import * as echarts from "echarts";
import SubTtile from "../../../components/SubTitle/index";
export default {name: "",components: {SubTtile},props: {title: {type: String,default: ""},id: {type: String,default: `bar${new Date().getTime()}`}},data() {return {dateDate: [],// 恒升bData: [],// 祥荣jData: [],// 德润zData: [],// 鑫义xData: [],// 创源lData: [],// 东风镁业tData: [],// 泰和hData: [],// 天元yData: [],beginDate:[],endDate:[],itemData: {},category :[],ddate :[],price :[],seriesData:[]};},created(){this.beginDate = this.dayjs().subtract(14,'day').format('YYYY-MM-DD')this.endDate = this.dayjs().subtract(0,'day').format('YYYY-MM-DD')},mounted() {this.getDlSupplyPriceCompare()},methods: {async getDlSupplyPriceCompare(){let category=[]let ddate =[]let price =[]const res = await reqDlSupplyPriceCompare(this.beginDate,this.endDate)res.data.forEach(item => {category.push(item.category)ddate.push(item.ddate)price.push(parseFloat(item.price).toFixed(2))})// console.log(new Set(category), new Set(ddate), price, 'shuji')this.category=[...new Set(category)]this.ddate=[ ... new Set(ddate)]this.category.forEach(el => {this.itemData[el] = []res.data.forEach((item, f) => {if (el === item.category) {// ddate.forEach((j,i)=>{})let a =  this.ddate.indexOf(item.ddate)//  this.itemData[el][a] = parseFloat(item.price).toFixed(2)this.itemData[el][a]=item.price// this.itemData[el].push(item.price)}})})//  console.log(this.itemData, 'ppp')for(let i in this.itemData){this.seriesData.push({type: "line",name: i,smooth: true, //是否平滑showAllSymbol: true,symbol: "circle",symbolSize: 2,// lineStyle: {//   normal: {//     color: "#33e5ba",//     shadowColor: "rgba(0, 0, 0, 0)",//     shadowBlur: 0,//     shadowOffsetY: 5,//     shadowOffsetX: 5//   }// },label: {show: false,position: "top",textStyle: {color: "#fff",fontSize: 14}},// itemStyle: {//   color: "",//   borderColor: "rgb(0,115,100)",//   borderWidth: 0,//   shadowColor: "rgba(0, 0, 0, 0)",//   shadowBlur: 0,//   shadowOffsetY: 0,//   shadowOffsetX: 0// },tooltip: {show: true},// data: this.bDatadata: this.itemData[i]},)}// res.data.forEach((item,i)=>{// let arr = []// arr[0] = item.ddate.substring(6)// const index = this.dateDate.indexOf(item.ddate.substring(6))// if(index < 0){//   this.dateDate.push(arr[0])// }// if(item.category === ''){//   let a = (this.dateDate).indexOf(item.ddate.substring(6))//   this.bData[a] = parseFloat(item.price).toFixed(2)// }// else if(item.category === '祥荣'){//   let b = (this.dateDate).indexOf(item.ddate.substring(6))//   this.jData[b] = parseFloat(item.price).toFixed(2)// }else if(item.category === '德润'){//   let c = (this.dateDate).indexOf(item.ddate.substring(6))//   this.zData[c] = parseFloat(item.price).toFixed(2)// }else if(item.category === '鑫义'){//   let d = (this.dateDate).indexOf(item.ddate.substring(6))//   this.xData[d] = parseFloat(item.price).toFixed(2)// }else if(item.category === '创源'){//   let e = (this.dateDate).indexOf(item.ddate.substring(6))//   this.lData[e] = parseFloat(item.price).toFixed(2)// }else if(item.category === '东风镁业'){//   let f = (this.dateDate).indexOf(item.ddate.substring(6))//   this.tData[f] = parseFloat(item.price).toFixed(2)// }else if(item.category === '泰和'){//   let g = (this.dateDate).indexOf(item.ddate.substring(6))//   this.hData[g] = parseFloat(item.price).toFixed(2)// }else{//   let h = (this.dateDate).indexOf(item.ddate.substring(6))//   this.yData[h] = parseFloat(item.price).toFixed(2)// }// })},firstOilChart() {let myChart = echarts.init(this.$refs[this.id]);let option = {legend: {left: 0,icon: "rect",itemWidth: 10,itemHeight: 10,padding: [10, 0],textStyle: {color: "#fff",fontSize: 12}},tooltip: {// 坐标轴触发trigger: "axis",backgroundColor: "rgba(48,142,213,0.7)",axisPointer: {lineStyle: {color: {type: "linear",x: 0,y: 0,x2: 0,y2: 1,colorStops: [{offset: 0,color: "rgba(0, 255, 233,0)"},{offset: 0.5,color: "rgba(255, 255, 255,1)"},{offset: 1,color: "rgba(0, 255, 233,0)"}],global: false}}}},grid: {top: "14%",left: "0%",right: "0%",bottom: "0%",containLabel: true},xAxis: [{type: "category",axisLine: {show: true,lineStyle: {color: "rgba(17,100,157,0.3)"}},splitArea: {color: "#fff",lineStyle: {color: "white"}},axisLabel: {textStyle: {fontFamily: "Microsoft YaHei",color: "#fff"},align: "right"},// 是否显示分隔线splitLine: {show: false},//坐标轴两边留白策略boundaryGap: false,data: this.ddate}],yAxis: {type: "value",axisLine: {//文字颜色show: false,lineStyle: {color: "rgba(17,100,157,0.3)"}},splitLine: {//线条颜色show: true,lineStyle: {color: "rgba(255,255,255,0.1)"}},axisLabel: {formatter: value => {return value;},textStyle: {color: "#fff"}},min: function(value) {return value.min - 20;}},// 系列列表series:this.seriesData// series: [//   {//     type: "line",//     name: "恒升",//     smooth: true, //是否平滑//     showAllSymbol: true,//     symbol: "circle",//     symbolSize: 2,//     lineStyle: {//       normal: {//         color: "#33e5ba",//         shadowColor: "rgba(0, 0, 0, 0)",//         shadowBlur: 0,//         shadowOffsetY: 5,//         shadowOffsetX: 5//       }//     },//     label: {//       show: false,//       position: "top",//       textStyle: {//         color: "#fff",//         fontSize: 14//       }//     },//     itemStyle: {//       color: "#33e5ba",//       borderColor: "rgb(0,115,100)",//       borderWidth: 0,//       shadowColor: "rgba(0, 0, 0, 0)",//       shadowBlur: 0,//       shadowOffsetY: 0,//       shadowOffsetX: 0//     },//     tooltip: {//       show: true//     },//     data: this.bData//   },//   {//     type: "line",//     name: "祥荣",//     smooth: true, //是否平滑//     showAllSymbol: true,//     symbol: "circle",//     symbolSize: 2,//     lineStyle: {//       normal: {//         color: "#34d1fe",//         shadowColor: "rgba(0, 0, 0, 0)",//         shadowBlur: 0,//         shadowOffsetY: 5,//         shadowOffsetX: 5//       }//     },//     label: {//       show: false,//       position: "top",//       textStyle: {//         color: "#fff",//         fontSize: 14//       }//     },//     itemStyle: {//       color: "#34d1fe",//       borderColor: "rgb(0,115,100)",//       borderWidth: 0,//       shadowColor: "rgba(0, 0, 0, 0)",//       shadowBlur: 0,//       shadowOffsetY: 0,//       shadowOffsetX: 0//     },//     tooltip: {//       show: true//     },//     data: this.jData//   },//   {//     type: "line",//     name: "德润",//     smooth: true, //是否平滑//     showAllSymbol: true,//     symbol: "circle",//     symbolSize: 2,//     lineStyle: {//       normal: {//         color: "#eee632",//         shadowColor: "rgba(0, 0, 0, 0)",//         shadowBlur: 0,//         shadowOffsetY: 5,//         shadowOffsetX: 5//       }//     },//     label: {//       show: false,//       position: "top",//       textStyle: {//         color: "#fff",//         fontSize: 14//       }//     },//     itemStyle: {//       color: "#eee632",//       borderColor: "rgb(0,115,100)",//       borderWidth: 0,//       shadowColor: "rgba(0, 0, 0, 0)",//       shadowBlur: 0,//       shadowOffsetY: 0,//       shadowOffsetX: 0//     },//     tooltip: {//       show: true//     },//     data: this.zData//   },//   {//     type: "line",//     name: "鑫义",//     smooth: true, //是否平滑//     showAllSymbol: true,//     symbol: "circle",//     symbolSize: 2,//     lineStyle: {//       normal: {//         color: "#ff681e",//         shadowColor: "rgba(0, 0, 0, 0)",//         shadowBlur: 0,//         shadowOffsetY: 5,//         shadowOffsetX: 5//       }//     },//     label: {//       show: false,//       position: "top",//       textStyle: {//         color: "#fff",//         fontSize: 14//       }//     },//     itemStyle: {//       color: "#ff681e",//       borderColor: "rgb(0,115,100)",//       borderWidth: 0,//       shadowColor: "rgba(0, 0, 0, 0)",//       shadowBlur: 0,//       shadowOffsetY: 0,//       shadowOffsetX: 0//     },//     tooltip: {//       show: true//     },//     data: this.xData//   },//   {//     type: "line",//     name: "创源",//     smooth: true, //是否平滑//     showAllSymbol: true,//     symbol: "circle",//     symbolSize: 2,//     lineStyle: {//       normal: {//         color: "#ff3a52",//         shadowColor: "rgba(0, 0, 0, 0)",//         shadowBlur: 0,//         shadowOffsetY: 5,//         shadowOffsetX: 5//       }//     },//     label: {//       show: false,//       position: "top",//       textStyle: {//         color: "#fff",//         fontSize: 14//       }//     },//     itemStyle: {//       color: "#ff3a52",//       borderColor: "rgb(0,115,100)",//       borderWidth: 0,//       shadowColor: "rgba(0, 0, 0, 0)",//       shadowBlur: 0,//       shadowOffsetY: 0,//       shadowOffsetX: 0//     },//     tooltip: {//       show: true//     },//     data: this.lData//   },//   {//     type: "line",//     name: "东风镁业",//     smooth: true, //是否平滑//     showAllSymbol: true,//     symbol: "circle",//     symbolSize: 2,//     lineStyle: {//       normal: {//         color: "#385eff",//         shadowColor: "rgba(0, 0, 0, 0)",//         shadowBlur: 0,//         shadowOffsetY: 5,//         shadowOffsetX: 5//       }//     },//     label: {//       show: false,//       position: "top",//       textStyle: {//         color: "#fff",//         fontSize: 14//       }//     },//     itemStyle: {//       color: "#385eff",//       borderColor: "rgb(0,115,100)",//       borderWidth: 0,//       shadowColor: "rgba(0, 0, 0, 0)",//       shadowBlur: 0,//       shadowOffsetY: 0,//       shadowOffsetX: 0//     },//     tooltip: {//       show: true//     },//     data: this.tData//   },//   {//     type: "line",//     name: "泰和",//     smooth: true, //是否平滑//     showAllSymbol: true,//     symbol: "circle",//     symbolSize: 2,//     lineStyle: {//       normal: {//         color: "#0ef946",//         shadowColor: "rgba(0, 0, 0, 0)",//         shadowBlur: 0,//         shadowOffsetY: 5,//         shadowOffsetX: 5//       }//     },//     label: {//       show: false,//       position: "top",//       textStyle: {//         color: "#fff",//         fontSize: 14//       }//     },//     itemStyle: {//       color: "#0ef946",//       borderColor: "rgb(0,115,100)",//       borderWidth: 0,//       shadowColor: "rgba(0, 0, 0, 0)",//       shadowBlur: 0,//       shadowOffsetY: 0,//       shadowOffsetX: 0//     },//     tooltip: {//       show: true//     },//     data: this.hData//   },//   {//     type: "line",//     name: "天元",//     smooth: true, //是否平滑//     showAllSymbol: true,//     symbol: "circle",//     symbolSize: 2,//     lineStyle: {//       normal: {//         color: "#fff",//         shadowColor: "rgba(0, 0, 0, 0)",//         shadowBlur: 0,//         shadowOffsetY: 5,//         shadowOffsetX: 5//       }//     },//     label: {//       show: false,//       position: "top",//       textStyle: {//         color: "#fff",//         fontSize: 14//       }//     },//     itemStyle: {//       color: "#fff",//       borderColor: "rgb(0,115,100)",//       borderWidth: 0,//       shadowColor: "rgba(0, 0, 0, 0)",//       shadowBlur: 0,//       shadowOffsetY: 0,//       shadowOffsetX: 0//     },//     tooltip: {//       show: true//     },//     data: this.yData//   },// ]};myChart.setOption(option);// echarts自适应屏幕大小window.addEventListener("resize", function() {myChart.resize();});}},watch:{// dateDate(){//   this.firstOilChart()// }ddate (){this.firstOilChart()}}
};
</script><style lang="less" scoped>
.pricePlatT_firstOilChart {width: 100%;height: calc(100% - 40px);
}
#pricePlatT_firstOilChart {width: 100%;height: 100%;margin-top: 26px;
}
</style>

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

相关文章

2022-2028年中国DMF行业市场研究及前瞻分析报告

【报告类型】产业研究 【报告价格】4500起 【出版时间】即时更新&#xff08;交付时间约3个工作日&#xff09; 【发布机构】智研瞻产业研究院 【报告格式】PDF版 本报告介绍了中国DMF行业市场行业相关概述、中国DMF行业市场行业运行环境、分析了中国DMF行业市场行业的现状…

今日股市板块利好早知道,全球科技巨头聚齐联手保护云数据

早上好&#xff0c;以下是今日热点前瞻 1、国内醋酸供给面持续向好 市场价格大幅上涨 7月下旬以来国内醋酸价格持续大幅上涨。周四&#xff0c;华东、西北等地继续上调报价&#xff0c;幅度在100-330元/吨。国内醋酸最新参考价报3409元/吨&#xff0c; 较上一日大涨4.54%&am…

研报精选230306

目录 【行业230306东亚前海证券】食品饮料行业2023年年度投资策略&#xff1a;复苏在途&#xff0c;蓄势待发 【行业230306国金证券】基础化工行业研究&#xff1a;MDI价格上行&#xff0c;新一轮国企改革在即 【行业230306中银证券】华为汽车产业链深度报告&#xff1a;三种合…

2023-2028年中国合成氨行业发展前景与投资规划分析报告

本报告由锐观咨询重磅推出&#xff0c;对中国合成氨行业的发展现状、竞争格局及市场供需形势进行了具体分析&#xff0c;并从行业的政策环境、经济环境、社会环境及技术环境等方面分析行业面临的机遇及挑战。还重点分析了重点企业的经营现状及发展格局&#xff0c;并对未来几年…

九龙证券|北上资金连续10日“跑步入场”,1月净流入已逼近2022全年

1月以来&#xff0c;北上资金净流入规划已接近2022全年。 半导体概念股集体大涨 1月17日&#xff0c;沪指缩量小幅调整&#xff0c;收跌0.1%&#xff1b;深成指涨0.13%&#xff0c;创业板指收涨0.24%&#xff0c;科创50涨逾1%。 板块方面&#xff0c;半导体及元件板块继续走强…

明峰医疗IPO终止:亏损超过14亿元,王瑶法、潘华素夫妇为实控人

近日&#xff0c;上海证券交易所科创板披露的信息显示&#xff0c;明峰医疗系统股份有限公司&#xff08;下称“明峰医疗”&#xff09;向上海证券交易所提交了撤回上市申请文件的申请&#xff0c;保荐人海通证券提交了撤回保荐的申请。 因此&#xff0c;上海证券交易所决定终…

恒生电子

恒生是面试的第二家公司,虽然不是大公司,但是也想去积累下经验,相比中软,恒生更偏向于自己的业务,有同学进去实习过,恒生的开发不是很好,最好就不要去,不过如果你想也在金融界发展的话,恒生不失为一个好的选择,至少可以熟悉业界背景。 笔试: 分为两部分,一部分是基…

下沙恒升

杭州的人才市场&#xff0c;有市人才和省人才&#xff0c;几乎天天像个集市。去了两次&#xff0c;就再也没有去的欲望了。里面人潮汹涌&#xff0c;费了半天排除&#xff0c;等来的差不多就是一句苍白的等候通知。后来才明白&#xff0c;在这里面设摊的很多单位&#xff0c;来…