useChartRender.ts 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512
  1. import { reactive, toRefs, onMounted, ref,watch } from "vue";
  2. import _ from "lodash";
  3. import {
  4. IChartType,
  5. IDataProps,
  6. IParams,
  7. ISeasonDataItemProps,
  8. } from "@/types";
  9. import Highcharts from "highcharts";
  10. import { defaultOpts, seasonOptions } from "@/utils/chartOptions";
  11. import moment from "moment";
  12. import router from '@/router'
  13. //获取RGBA的透明度
  14. const parseRgbaColor = (color='rgba(51, 51, 51, 1)') => {
  15. const arr = color.match(/(\d(\.\d+)?)+/g) || ['','','',1];
  16. return parseFloat((arr[3]||1)+'')
  17. }
  18. // 散点x
  19. const scatterXAxis = {
  20. tickPosition: "inside",
  21. lineColor: "#bfbfbf",
  22. tickColor: "#bfbfbf",
  23. tickLength: 5,
  24. ordinal: false,
  25. type: "linear",
  26. };
  27. //基础y轴
  28. const basicYAxis = {
  29. tickLength: 5,
  30. lineWidth: 1,
  31. lineColor: "#bfbfbf",
  32. tickColor: "#bfbfbf",
  33. // offset: 0,
  34. visible: true,
  35. gridLineWidth: 0,
  36. tickPosition: "inside",
  37. endOnTick: false,
  38. startOnTick: false,
  39. showLastLabel: true,
  40. };
  41. interface StateProps {
  42. chartLimit: {
  43. min?: number;
  44. max?: number;
  45. x_min?:number;
  46. x_max?:number;
  47. rightMin?:number;
  48. rightMax?:number;
  49. rightTwoMin?:number;
  50. rightTwoMax?:number;
  51. }
  52. dataList: any[];
  53. chartInfo: any;
  54. DataResp:any
  55. }
  56. /**
  57. * useChartRender 处理图表渲染 返回options
  58. * @param Data 详情数据 lange中英文
  59. * @param {
  60. * Source 1 //ETA图 ChartType: 1曲线图 2季节图 3面积图 4柱状图 5散点图 6组合图 7柱形 10截面散点 11雷达图
  61. * 2 商品价格
  62. * 3 相关性
  63. * 4 滚动相关性
  64. * 5 商品利润
  65. * 6 拟合方程
  66. * 7 统计特征/标准差
  67. * 8 统计特征/百分位
  68. * 9 统计特征/频率
  69. * 10 跨品种分析
  70. * }
  71. *
  72. */
  73. //依赖数据
  74. const state = reactive<StateProps>({
  75. chartInfo: {},
  76. dataList: [],
  77. chartLimit: {
  78. min:0, //左轴上下限
  79. max:0,
  80. rightMin:0,//右轴上下限
  81. rightMax:0,
  82. rightTwoMin:0,//右二轴上下限
  83. rightTwoMax:0,
  84. },
  85. DataResp:null,
  86. })
  87. const language = ref('')
  88. const routeQuery = ref<any>({});//路由参
  89. watch(() => router.currentRoute.value.query,(nval) => {
  90. routeQuery.value = nval
  91. })
  92. export const useChartRender = (Data,lang='zh',) => {
  93. state.chartInfo = Data.ChartInfo
  94. state.dataList = [1,11].includes(Data.ChartInfo.Source) ? Data.EdbInfoList : [Data.EdbInfoList[0]];
  95. language.value = lang
  96. state.DataResp=Data.DataResp
  97. let chartOptions:any;
  98. //eta图
  99. if ([1,11].includes(Data.ChartInfo.Source)) {
  100. setLimitData(state.dataList,Data)
  101. const typeMap = {
  102. 1: setDefaultLineOptions,
  103. 2: setSeasonOptions,
  104. 3: setStackOrCombinChart,
  105. 4: setStackOrCombinChart,
  106. 5: setScatterChartOptions,
  107. 6: setStackOrCombinChart,
  108. 7: initBarData,
  109. 10: initSectionScatterData,
  110. 11: initRadarData,
  111. 14: setSectionalCombinationChart,
  112. };
  113. chartOptions = typeMap[state.chartInfo.ChartType] && typeMap[state.chartInfo.ChartType](Data);
  114. }else {
  115. //其他source图
  116. const sourceTypeMap = {
  117. 2: initCommodityData,
  118. 3: initRelevanceChartData,
  119. 4: initStatisticChartData,
  120. 5: initCommodityData,
  121. 6: initFittingEquation,
  122. 7: initStatisticChartData,
  123. 8: initStatisticChartData,
  124. 9: initStatisticChartData,
  125. 10: initCrossVarietyChartData,
  126. 12:initIntervalAnalysisChartData
  127. };
  128. chartOptions = sourceTypeMap[Data.ChartInfo.Source] &&
  129. sourceTypeMap[Data.ChartInfo.Source](Data);
  130. }
  131. return chartOptions
  132. };
  133. // 截面组合图
  134. function setSectionalCombinationChart(e){
  135. /* 主题样式*/
  136. const chartTheme = e.ChartInfo.ChartThemeStyle ? JSON.parse(e.ChartInfo.ChartThemeStyle) : null;
  137. const {XDataList,UnitList,SeriesList,IsHeap}=e.DataResp;
  138. //x轴
  139. const xAxis={
  140. categories:XDataList.map(_=>language.value=='zh'?_.Name:_.NameEn),
  141. tickWidth: 1,
  142. labels: {
  143. style:{
  144. ...chartTheme&&chartTheme.xAxisOptions.style
  145. },
  146. },
  147. plotBands: setAxisPlotAreas(3),
  148. plotLines: setAxisPlotLines(3)
  149. }
  150. let yAxis=[]
  151. let seriesData=[]
  152. //有右二轴时排个序 按照左 右 右2的顺序
  153. const chartData = SeriesList.some(_ =>_.IsAxis===2) ? changeEdbOrder(SeriesList) : _.cloneDeep(SeriesList);
  154. chartData.forEach((item,index)=>{
  155. //轴位置值相同的下标
  156. const sameSideIndex = chartData.findIndex(
  157. (i) => i.IsAxis === item.IsAxis
  158. );
  159. const yTitleMap={
  160. 1:['LeftName','LeftNameEn'],
  161. 0:['RightName','RightNameEn'],
  162. 2:['RightTwoName','RightTwoNameEn'],
  163. }
  164. let minLimit = 0,maxLimit = 0
  165. const limitMap = {
  166. 0:['rightMin','rightMax'],
  167. 1:['min','max'],
  168. 2:['rightTwoMin','rightTwoMax']
  169. }
  170. if(limitMap[item.IsAxis]){
  171. minLimit = state.chartLimit[`${limitMap[item.IsAxis][0]}`]||0
  172. maxLimit = state.chartLimit[`${limitMap[item.IsAxis][1]}`]||0
  173. }
  174. let yItem = {
  175. ...basicYAxis,
  176. title: {
  177. text: UnitList[yTitleMap[item.IsAxis][0]],
  178. textCh:UnitList[yTitleMap[item.IsAxis][0]], // 中文
  179. // 中文不存在,无论英文有无都显示空
  180. textEn:UnitList[yTitleMap[item.IsAxis][0]]?UnitList[yTitleMap[item.IsAxis][1]]:'', // 英文
  181. style:{
  182. ...chartTheme&&chartTheme.yAxisOptions.style
  183. },
  184. align: 'high',
  185. rotation: 0,
  186. y: -12,
  187. // x: (item.IsAxis===0 && this.rightTwoIndex>-1) ? -chartData[this.rightTwoIndex].Unit.length*12 : 0,
  188. textAlign: item.IsAxis===1 ? 'left' : 'right',
  189. reserveSpace: false
  190. },
  191. labels: {
  192. formatter: function (ctx) {
  193. return ctx.value;
  194. },
  195. align: 'center',
  196. x: [0,2].includes(item.IsAxis) ? 5 : -5,
  197. style: {
  198. ...chartTheme&&chartTheme.yAxisOptions.style,
  199. }
  200. },
  201. opposite: [0,2].includes(item.IsAxis),
  202. min: Number(minLimit),
  203. max: Number(maxLimit),
  204. tickWidth: 1,
  205. visible: sameSideIndex === index,
  206. plotBands: setAxisPlotAreas(item.IsAxis),
  207. plotLines: setAxisPlotLines(item.IsAxis)
  208. };
  209. //堆叠图的yAxis必须一致 数据列所对应的y轴
  210. let serie_yIndex = index;
  211. if(IsHeap==1) {
  212. // 类型为堆叠图时公用第一个指标y轴
  213. serie_yIndex = 0;
  214. }
  215. //数据列
  216. let dataArr=item.DataList||[]
  217. // 根据NoDataEdbIndex 将对应位置的值置为null
  218. dataArr.forEach((i,index)=>{
  219. if(item.NoDataEdbIndex.includes(index)){
  220. dataArr[index]=null
  221. }
  222. })
  223. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  224. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  225. let obj={
  226. data:dataArr,
  227. type: item.ChartStyle||'',
  228. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  229. chartType:'linear',
  230. yAxis: serie_yIndex,
  231. name:item.SeriesName,
  232. nameZh:item.SeriesName,
  233. nameEn:item.SeriesNameEn,
  234. unitName:UnitList[yTitleMap[item.IsAxis][0]],
  235. unitNameCh:UnitList[yTitleMap[item.IsAxis][0]],
  236. unitNameEn:UnitList[yTitleMap[item.IsAxis][0]]?UnitList[yTitleMap[item.IsAxis][1]]:'',
  237. color: item.ChartColor,
  238. lineWidth: Number(item.ChartWidth)||(chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth),
  239. borderWidth: 1,
  240. borderColor: item.ChartColor,
  241. marker: {//展示数据点
  242. enabled:item.ChartStyle!='column'&&item.IsPoint?true:false,
  243. radius: (chartTheme&&chartTheme.lineOptionList[lineIndex].radius)||5,
  244. },
  245. dataLabels: {//展示数值
  246. enabled: item.IsNumber?true:false,
  247. align:item.ChartStyle=='column'?'center':undefined,
  248. y:item.ChartStyle=='column'?-20:0,
  249. inside: item.ChartStyle=='column'?false:undefined,
  250. crop: item.ChartStyle=='column'?false:true,
  251. },
  252. stacking:IsHeap==1?'normal':undefined,
  253. zIndex: ['line','spline'].includes(item.ChartStyle) ? 1 : 0, //防止组合图曲线被遮住
  254. }
  255. yAxis.push(yItem)
  256. seriesData.push(obj)
  257. })
  258. const tooltip={
  259. formatter:function () {
  260. let str=`<b>${this.points[0].x}</b>`
  261. this.points.forEach(item=>{
  262. const sObj=seriesData.find(_=>_.name===item.series.name)
  263. str=str+`<br><span style="color:${item.color}">\u25CF</span>${sObj.name}:${item.y} ${sObj.unitNameCh}`
  264. })
  265. return str
  266. },
  267. formatterCh:function () {
  268. let str=`<b>${this.points[0].x}</b>`
  269. this.points.forEach(item=>{
  270. const sObj=seriesData.find(_=>_.name===item.series.name)
  271. str=str+`<br><span style="color:${item.color}">\u25CF</span>${sObj.nameCh}:${item.y} ${sObj.unitNameCh}`
  272. })
  273. return str
  274. },
  275. formatterEn:function () {
  276. let str=`<b>${this.points[0].x}</b>`
  277. this.points.forEach(item=>{
  278. const sObj=seriesData.find(_=>_.name===item.series.name)
  279. str=str+`<br><span style="color:${item.color}">\u25CF</span>${sObj.nameEn}:${item.y} ${sObj.unitNameEn}`
  280. })
  281. return str
  282. },
  283. shared:true
  284. }
  285. return {
  286. title: {
  287. text:''
  288. },
  289. tooltip,
  290. series: seriesData,
  291. yAxis: yAxis,
  292. xAxis,
  293. }
  294. }
  295. /* 曲线图 */
  296. const setDefaultLineOptions = () => {
  297. const { dataList,chartInfo } = state;
  298. /* 主题样式*/
  299. const chartTheme = chartInfo.ChartThemeStyle ? JSON.parse(chartInfo.ChartThemeStyle) : null;
  300. //拼接标题 数据列
  301. let data = [] as any[],ydata = [] as any[],minTimeArr: number[] = [],maxTimeArr: number[] = [];
  302. let rightTwoIndex = dataList.findIndex(item => item.IsAxis ===2);
  303. // const chartData = _.cloneDeep(dataList);
  304. //有右二轴时排个序 按照左 右 右2的顺序
  305. let chartData = dataList.some(_ =>_.IsAxis===2) ? changeEdbOrder(dataList) : _.cloneDeep(dataList);
  306. chartData.forEach((item:IDataProps ,index:number) => {
  307. //轴位置值相同的下标
  308. let sameSideIndex = chartData.findIndex(
  309. (i:IDataProps) => i.IsAxis === item.IsAxis
  310. );
  311. //获取对应轴的上下限
  312. //非ETA图库图表也不设置自定义上下限,相关性和统计特征也会用到曲线图
  313. //若chartInfo.Source为1,需在之前调用setLimitData
  314. const isETASource = [1,11,12].includes(state.chartInfo.Source)
  315. let minLimit = 0,maxLimit = 0
  316. if(isETASource){
  317. const limitMap = {
  318. 0:['rightMin','rightMax'],
  319. 1:['min','max'],
  320. 2:['rightTwoMin','rightTwoMax']
  321. }
  322. if(limitMap[item.IsAxis]){
  323. minLimit = state.chartLimit[`${limitMap[item.IsAxis][0]}`]||0
  324. maxLimit = state.chartLimit[`${limitMap[item.IsAxis][1]}`]||0
  325. }
  326. }else{
  327. minLimit = dataList[sameSideIndex].MinData
  328. maxLimit = dataList[sameSideIndex].MaxData
  329. }
  330. //y轴
  331. const textZh = item.ConvertUnit||item.Unit
  332. const textEn = textZh?item.ConvertEnUnit||item.UnitEn||item.ConvertUnit||item.Unit:''
  333. let yItem = {
  334. ...basicYAxis,
  335. labels: {
  336. formatter: function (ctx: any) {
  337. let val = ctx.value;
  338. return sameSideIndex !== index ? '' : val;
  339. },
  340. align: 'center',
  341. x: [0,2].includes(item.IsAxis) ? 5 : -5,
  342. style: {
  343. ...chartTheme&&chartTheme.yAxisOptions.style,
  344. }
  345. },
  346. title: {
  347. text:language.value=='zh'?sameSideIndex !== index ? '' : `${textZh}`:textEn,
  348. style:{
  349. ...chartTheme&&chartTheme.yAxisOptions.style
  350. },
  351. align: 'high',
  352. rotation: 0,
  353. y: -12,
  354. x: (item.IsAxis===0 && rightTwoIndex>-1) ? -chartData[rightTwoIndex].Unit.length*12 : 0,
  355. textAlign: item.IsAxis===1 ? 'left' : 'right',
  356. reserveSpace: false
  357. },
  358. opposite: [0,2].includes(item.IsAxis),
  359. reversed: item.IsOrder,
  360. min: Number(minLimit),
  361. max: Number(maxLimit),
  362. tickWidth: 1,
  363. visible: sameSideIndex === index,
  364. plotBands: setAxisPlotAreas(item.IsAxis),
  365. plotLines: setAxisPlotLines(item.IsAxis)
  366. }
  367. // //拼接标题 判断相同指标名称拼接来源
  368. let dynamic_title = item.EdbName;
  369. let dynamic_arr = chartData.filter(
  370. (item: IDataProps) => dynamic_title === item.EdbName
  371. );
  372. // 拼接配置 IsAxis左轴1 右轴0 IsOrder正序false 逆序true EdbInfoType是否是领先指标
  373. let dynamic_tag = concatDynamicTag(item)
  374. // 英文后缀
  375. let dynamic_tag_en = concatDynamicTag(item,'en')
  376. //数据列
  377. let nameCh:String = dynamic_arr.length > 1
  378. ? `${item.EdbAliasName||item.EdbName}(${item.SourceName})${dynamic_tag}`
  379. : `${item.EdbAliasName||item.EdbName}${dynamic_tag}`
  380. let nameEn:String=item.EdbNameEn?`${item.EdbNameEn}${dynamic_tag_en}`:''
  381. let name :String=language.value == 'zh'?nameCh:nameEn
  382. //预测指标配置
  383. let predict_params = item.EdbInfoCategoryType === 1 ? getPredictParams(item) : {};
  384. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  385. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  386. let obj = {
  387. data: [] as any[],
  388. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || 'spline',
  389. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  390. yAxis: sameSideIndex,
  391. name,
  392. color: item.ChartColor,
  393. lineWidth: Number(item.ChartWidth)||(chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth)||1,
  394. marker:chartTheme && chartTheme.lineOptionList[lineIndex].dataMark && chartTheme.lineOptionList[lineIndex].dataMark!='none'?{
  395. enabled:true,
  396. symbol: chartTheme.lineOptionList[lineIndex].markType || 'circle',
  397. fillColor:chartTheme.lineOptionList[lineIndex].markColor,
  398. radius: chartTheme.lineOptionList[lineIndex].markSize
  399. }:{},
  400. ...predict_params
  401. };
  402. item.DataList = item.DataList || []
  403. for (let i of item.DataList) {
  404. obj.data.push([i.DataTimestamp, i.Value]);
  405. }
  406. if(item.DataList.length){
  407. minTimeArr.push(item.DataList[0].DataTimestamp)
  408. maxTimeArr.push(item.DataList[item.DataList.length-1].DataTimestamp)
  409. }
  410. data.push(obj);
  411. ydata.push(yItem);
  412. })
  413. // 范围为1年内 x轴显示为月/日 否则默认年/月
  414. let xAxis:any = {};
  415. const isLessThanOneYear:boolean = xTimeDiffer();
  416. let minTime: number=Math.min(...minTimeArr);
  417. let maxTime=Math.max(...maxTimeArr);
  418. let step = setXaxisStep(maxTime-minTime);
  419. xAxis = {
  420. ...defaultOpts.xAxis,
  421. tickInterval: screen.value === 'phone' ? step : undefined,
  422. labels: {
  423. formatter: function (ctx: any) {
  424. return isLessThanOneYear
  425. ? Highcharts.dateFormat('%m/%d', ctx.value)
  426. : Highcharts.dateFormat('%y/%m', ctx.value);
  427. },
  428. style: {
  429. ...chartTheme&&chartTheme.xAxisOptions.style
  430. }
  431. },
  432. plotBands: setAxisPlotAreas(3,'datetime'),
  433. plotLines: setAxisPlotLines(3,'datetime')
  434. }
  435. let options:any = {};
  436. options = {
  437. series: data,
  438. yAxis: ydata,
  439. xAxis
  440. };
  441. //滚动相关性独立tooltip
  442. if(chartInfo.Source === 4) {
  443. const relevanceUnitEnMap={
  444. '年': 'Year',
  445. '季': 'Season',
  446. '月': 'Month',
  447. '周': 'Week',
  448. '天': 'Day',
  449. }
  450. const { LeadValue,LeadUnit } = statisticFrequencyRenderData.value;
  451. options.tooltip = {
  452. formatter: function() {
  453. let that:any = this;
  454. let str = '';
  455. if(language.value=='zh'){
  456. str = `${Highcharts.dateFormat('%Y/%m/%d',that.x)}<br><p>相关性系数:${that.y.toFixed(4)}</p><br><p>领先${LeadValue+LeadUnit}</p>`
  457. }else{
  458. str = `${Highcharts.dateFormat('%Y/%m/%d',that.x)}<br><p>Correlation coefficient:${that.y.toFixed(4)}</p><br><p>lead${LeadValue+relevanceUnitEnMap[LeadUnit]}</p>`
  459. }
  460. return str
  461. },
  462. }
  463. }
  464. return options;
  465. }
  466. /* 季节图 */
  467. const screen = ref(document.body.clientWidth < 1200 ? 'phone' : 'pc');
  468. const setSeasonOptions = (data:any) => {
  469. const {RightAxis:SeasonRightConfig={}} = data.DataResp||{}
  470. const chartData = state.dataList[0];
  471. // 农历数据需要去除第一项 在ETA1.0.5之后,除了这里 农历和公历处理逻辑一样
  472. if(!chartData.DataList){
  473. return
  474. }
  475. const chartDataHandle=state.chartInfo.Calendar === '农历'?
  476. chartData.DataList.filter((item:ISeasonDataItemProps, index:number) => index > 0):
  477. chartData.DataList
  478. let seasonYdata:any[] = [],
  479. seasonData:any[] = [];
  480. //获取对应轴的上下限
  481. let minLimit = 0,maxLimit = 0,rightMin = 0,rightMax = 0
  482. minLimit = state.chartLimit.min||0
  483. maxLimit = state.chartLimit.max||0
  484. if(SeasonRightConfig.IsShow){
  485. rightMin = state.chartLimit.rightMin||0
  486. rightMax = state.chartLimit.rightMax||0
  487. }
  488. /* 主题样式*/
  489. const chartTheme = state.chartInfo.ChartThemeStyle ? JSON.parse(state.chartInfo.ChartThemeStyle) : null;
  490. // 跟颜色对应
  491. chartTheme && (chartTheme.lineOptionList=chartTheme.lineOptionList.reverse().slice(-chartDataHandle.length))
  492. let maxDateRange=0
  493. /*处理数据列 常规左轴*/
  494. for (let index in chartDataHandle) {
  495. console.log(index,'index');
  496. let j = chartDataHandle[index]
  497. //预测指标配置
  498. let predict_params = chartData.EdbInfoCategoryType === 1 ? getSeasonPredictParams(j.CuttingDataTimestamp) : {};
  499. // 图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  500. const lineIndex = chartTheme ? Number(index)%chartTheme.lineOptionList.length : index
  501. let serie_item = {
  502. data: [] as any[],
  503. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || chartData.ChartStyle,
  504. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  505. yAxis: 0,
  506. name: j.ChartLegend,
  507. lineWidth: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 1,
  508. marker:chartTheme && chartTheme.lineOptionList[lineIndex].dataMark && chartTheme.lineOptionList[lineIndex].dataMark!='none'?{
  509. enabled:true,
  510. symbol: chartTheme.lineOptionList[lineIndex].markType || 'circle',
  511. fillColor:chartTheme.lineOptionList[lineIndex].markColor,
  512. radius: chartTheme.lineOptionList[lineIndex].markSize
  513. }:{},
  514. ...predict_params
  515. };
  516. const data_array = _.cloneDeep(j.DataList)||[];
  517. let dateRange=0
  518. if(data_array.length>0){
  519. dateRange = data_array[data_array.length-1].DataTimestamp - data_array[0].DataTimestamp
  520. // 时间范围
  521. maxDateRange=Math.max(maxDateRange,dateRange)
  522. }
  523. data_array &&
  524. data_array.forEach((item: IParams) => {
  525. serie_item.data.push([item.DataTimestamp, item.Value]);
  526. });
  527. seasonData.push(serie_item);
  528. }
  529. //同期上下限/均线/标准差
  530. const {MaxMinLimits={},SamePeriodAverage={},SamePeriodStandardDeviation={}} = data.DataResp||{}
  531. if(MaxMinLimits.IsShow&&MaxMinLimits.List&&MaxMinLimits.List.length){
  532. let serieItem = {
  533. type:'arearange',//上下限是一个范围
  534. data:[] as any[],
  535. name:MaxMinLimits.Legend||'同期上下限',
  536. color:MaxMinLimits.Color||'#075EEE',
  537. fillOpacity:parseRgbaColor(MaxMinLimits.Color||'')>0.75?0.75:parseRgbaColor(MaxMinLimits.Color||'') //透明度最高0.75
  538. }
  539. console.log('serieItem?',serieItem.fillOpacity)
  540. MaxMinLimits.List.forEach((item:any)=>{
  541. serieItem.data.push([item.DataTimestamp,item.MinValue,item.MaxValue])
  542. })
  543. seasonData.push(serieItem)
  544. }
  545. if(SamePeriodAverage.IsShow&&SamePeriodAverage.List){
  546. let serieItem = {
  547. type:'line',
  548. data:[] as any [],
  549. lineWidth:SamePeriodAverage.LineWidth,
  550. dashStyle:SamePeriodAverage.LineType,
  551. name:SamePeriodAverage.Legend||'同期均值',
  552. color:SamePeriodAverage.Color||'#075EEE'
  553. }
  554. SamePeriodAverage.List.forEach((item:any)=>{
  555. serieItem.data.push([item.DataTimestamp,item.Value])
  556. })
  557. seasonData.push(serieItem)
  558. }
  559. if(SamePeriodStandardDeviation.IsShow&&SamePeriodStandardDeviation.List){
  560. let serieItem = {
  561. type:'arearange',//标准差也是一个范围
  562. data:[] as any [],
  563. name:SamePeriodStandardDeviation.Legend||'同期标准差',
  564. color:SamePeriodStandardDeviation.Color||'#075EEE',
  565. fillOpacity:parseRgbaColor(SamePeriodStandardDeviation.Color||'')>0.75?0.75:parseRgbaColor(SamePeriodStandardDeviation.Color||'')
  566. }
  567. SamePeriodStandardDeviation.List.forEach((item:any)=>{
  568. serieItem.data.push([item.DataTimestamp,item.MinValue,item.MaxValue])
  569. })
  570. seasonData.push(serieItem)
  571. }
  572. //右轴
  573. if(SeasonRightConfig.IsShow){
  574. //右轴的设置
  575. let serieConfig = SeasonRightConfig.Style==='column'?{
  576. //柱形
  577. type:'column',
  578. color:SeasonRightConfig.ChartColor
  579. }:{
  580. //标记点
  581. type:'spline',
  582. lineWidth:SeasonRightConfig.LineWidth,
  583. dashStyle:SeasonRightConfig.LineStyle,
  584. color:SeasonRightConfig.IsConnected?SeasonRightConfig.LineColor:'rgba(255, 255, 255, 0)',//没有连线颜色设置为透明
  585. marker:{
  586. enabled:true,
  587. symbol:SeasonRightConfig.Shape,
  588. fillColor:SeasonRightConfig.ChartColor,
  589. radius:SeasonRightConfig.Size
  590. },
  591. }
  592. let serieItem = {
  593. ...serieConfig,
  594. name:SeasonRightConfig.Legend||'右轴',
  595. data:[] as any[],
  596. yAxis:1,
  597. }
  598. const DataList = (SeasonRightConfig.IndicatorType===1?SeasonRightConfig.EdbInfoList[0].DataList:state.dataList[1].DataList)||[]
  599. DataList.forEach((item:any)=>{
  600. serieItem.data.push([item.DataTimestamp,item.Value])
  601. })
  602. seasonData.push(serieItem)
  603. }
  604. //y轴
  605. const textZh = chartData.ConvertUnit||chartData.Unit
  606. const textEn = textZh?chartData.ConvertEnUnit||chartData.UnitEn||chartData.ConvertUnit||chartData.Unit:''
  607. seasonYdata = [{
  608. ...defaultOpts.yAxis,
  609. labels: {
  610. formatter: function (ctx: any) {
  611. let val = ctx.value;
  612. return val;
  613. },
  614. align: 'center',
  615. style: {
  616. ...chartTheme&&chartTheme.yAxisOptions.style
  617. }
  618. },
  619. title: {
  620. text:language.value=='zh'?`${textZh}`:textEn,
  621. align: 'high',
  622. rotation: 0,
  623. y: -12,
  624. x: 0,
  625. textAlign: 'left',
  626. reserveSpace: false,
  627. style:{
  628. ...chartTheme&&chartTheme.yAxisOptions.style
  629. },
  630. },
  631. max: Number(maxLimit),
  632. min: Number(minLimit),
  633. plotBands: setAxisPlotAreas(1),
  634. plotLines: setAxisPlotLines(1)
  635. }];
  636. //如果有右轴,seasonYdata加上右轴
  637. if(SeasonRightConfig.IsShow){
  638. const rightEdb = (SeasonRightConfig.IndicatorType===1?SeasonRightConfig.EdbInfoList[0]:state.dataList[1])||{unit:''}
  639. //左轴同比:text为空或% 右轴指标:取指标单位
  640. if(SeasonRightConfig.IndicatorType===1){
  641. rightEdb.Unit = SeasonRightConfig.NumFormat===1?'%':''
  642. }else{
  643. rightEdb.Unit = state.dataList[1]&&(state.dataList[1].ConvertUnit||state.dataList[1].Unit)||''
  644. }
  645. seasonYdata.push({
  646. ...defaultOpts.yAxis,
  647. opposite: true,//右轴
  648. labels: {
  649. formatter: function (ctx: any) {
  650. let val = ctx.value;
  651. return val;
  652. },
  653. align: 'center',
  654. style: {
  655. ...chartTheme&&chartTheme.yAxisOptions.style
  656. }
  657. },
  658. title: {
  659. text: rightEdb.Unit||'',
  660. style:{
  661. ...chartTheme&&chartTheme.yAxisOptions.style
  662. },
  663. align: 'high',
  664. rotation: 0,
  665. y: -12,
  666. x: 0 ,
  667. textAlign: 'right',
  668. reserveSpace: false,
  669. },
  670. max: Number(rightMax),
  671. min: Number(rightMin),
  672. })
  673. }
  674. // 季节图x轴显示月/日
  675. const xAxis = {
  676. ...defaultOpts.xAxis,
  677. tickInterval: screen.value === 'phone' ? maxDateRange/6 || undefined : undefined,
  678. labels: {
  679. formatter: function (ctx: any) {
  680. return Highcharts.dateFormat('%m/%d', ctx.value);
  681. },
  682. style: {
  683. ...chartTheme&&chartTheme.xAxisOptions.style
  684. }
  685. },
  686. plotBands: setAxisPlotAreas(3,'datetime'),
  687. plotLines: setAxisPlotLines(3,'datetime')
  688. };
  689. const tooltip = {
  690. ...defaultOpts.tooltip,
  691. dateTimeLabelFormats: {
  692. // 时间格式化字符
  693. day: '%m/%d',
  694. week: '%m/%d',
  695. month: '%m/%d',
  696. year: '%m/%d',
  697. },
  698. xDateFormat: '%m/%d',
  699. }
  700. let colors = chartTheme&&chartTheme.colorsOptions.reverse();
  701. return {
  702. colors:colors.slice(-chartDataHandle.length),
  703. series: seasonData,
  704. yAxis: seasonYdata,
  705. xAxis,
  706. tooltip
  707. };
  708. }
  709. /* 堆叠图/组合图设置
  710. 本来和曲线图逻辑基本一致兼容下即可 为了以后便于维护和阅读还是拆开写吧
  711. */
  712. const setStackOrCombinChart = () => {
  713. const { dataList,chartInfo,DataResp } = state;
  714. /* 主题样式*/
  715. const chartTheme = state.chartInfo.ChartThemeStyle ? JSON.parse(state.chartInfo.ChartThemeStyle) : null;
  716. //拼接标题 数据列
  717. let data = [] as any[],ydata = [] as any[],minTimeArr: number[] = [],maxTimeArr: number[] = [];
  718. // const chartData = _.cloneDeep(dataList);
  719. //有右二轴时排个序 按照左 右 右2的顺序
  720. let chartData = dataList.some(_ =>_.IsAxis===2) ? changeEdbOrder(dataList) : _.cloneDeep(dataList);
  721. let ExtraConfig={}
  722. if(chartInfo.ChartType===3 && chartInfo.ExtraConfig){
  723. ExtraConfig=JSON.parse(chartInfo.ExtraConfig)
  724. }
  725. //支持的图表类型
  726. const chartTypeMap: IChartType = {
  727. 3: 'areaspline',
  728. 4: 'column',
  729. 6: ''
  730. };
  731. let chartStyle = chartTypeMap[chartInfo.ChartType];
  732. chartData.forEach((item:IDataProps ,index:number) => {
  733. //轴位置值相同的下标
  734. let sameSideIndex = chartData.findIndex(
  735. (i:IDataProps) => i.IsAxis === item.IsAxis
  736. );
  737. //堆叠图的yAxis必须一致 数据列所对应的y轴
  738. let serie_yIndex = index;
  739. if([4].includes(chartInfo.ChartType) || (chartInfo.ChartType ===3 && ExtraConfig?.IsHeap==1)) {
  740. // 类型为堆叠图时公用第一个指标y轴
  741. serie_yIndex = 0;
  742. } else if(chartInfo.ChartType ===6 && ['areaspline','column'].includes(item.ChartStyle)) {
  743. // 组合图找第一个堆叠柱状或面积的作为公用
  744. serie_yIndex = chartData.findIndex((i:IDataProps) => i.ChartStyle === item.ChartStyle);
  745. }
  746. //数据对应的y轴是公用轴则配置也共享
  747. item.IsAxis = serie_yIndex === index ? item.IsAxis : chartData[serie_yIndex].IsAxis;
  748. item.IsOrder = serie_yIndex === index ? item.IsOrder : chartData[serie_yIndex].IsOrder;
  749. // 右2轴下标
  750. let rightTwoIndex = [4].includes(chartInfo.ChartType)
  751. ? -1
  752. : dataList.findIndex(item => item.IsAxis===2);
  753. //获取对应轴的上下限
  754. let minLimit = 0,maxLimit = 0
  755. const limitMap = {
  756. 0:['rightMin','rightMax'],
  757. 1:['min','max'],
  758. 2:['rightTwoMin','rightTwoMax']
  759. }
  760. if(limitMap[item.IsAxis]){
  761. minLimit = state.chartLimit[`${limitMap[item.IsAxis][0]}`]||0
  762. maxLimit = state.chartLimit[`${limitMap[item.IsAxis][1]}`]||0
  763. }
  764. //y轴
  765. const textZh = item.ConvertUnit||item.Unit
  766. const textEn = textZh?item.ConvertEnUnit||item.UnitEn||item.ConvertUnit||item.Unit:''
  767. let yItem = {
  768. ...basicYAxis,
  769. labels: {
  770. formatter: function (ctx: any) {
  771. let val = ctx.value;
  772. return sameSideIndex !== index ? '' : chartInfo.ChartType===3&&ExtraConfig?.HeapWay==2?val+'%':val;
  773. },
  774. align: 'center',
  775. x: [0,2].includes(item.IsAxis) ? 5 : -5,
  776. style:{
  777. ...chartTheme&&chartTheme.yAxisOptions.style
  778. },
  779. },
  780. title: {
  781. text:language.value=='zh'?sameSideIndex !== index ? '' : `${textZh}`:textEn,
  782. // text: null,
  783. align: 'high',
  784. rotation: 0,
  785. y: -12,
  786. x: (item.IsAxis===0 && rightTwoIndex>-1) ? -chartData[rightTwoIndex].Unit.length*12 : 0,
  787. textAlign: item.IsAxis===1 ? 'left' : 'right',
  788. reserveSpace: false,
  789. style:{
  790. ...chartTheme&&chartTheme.yAxisOptions.style
  791. },
  792. },
  793. opposite: [0,2].includes(item.IsAxis),
  794. reversed: item.IsOrder,
  795. min: chartInfo.ChartType===3&&ExtraConfig?.HeapWay==2?null:Number(minLimit),
  796. max: chartInfo.ChartType===3&&ExtraConfig?.HeapWay==2?null:Number(maxLimit),
  797. tickWidth: sameSideIndex !== index ? 0 : 1,
  798. visible: serie_yIndex === index && sameSideIndex ===index,
  799. plotBands: setAxisPlotAreas(item.IsAxis),
  800. plotLines: setAxisPlotLines(item.IsAxis)
  801. }
  802. // //拼接标题 判断相同指标名称拼接来源
  803. let dynamic_title = item.EdbName;
  804. let dynamic_arr = chartData.filter(
  805. (item: IDataProps) => dynamic_title === item.EdbName
  806. );
  807. // 拼接配置 IsAxis左轴1 右轴0 IsOrder正序false 逆序true EdbInfoType是否是领先指标
  808. let dynamic_tag = concatDynamicTag(item)
  809. // 英文后缀
  810. let dynamic_tag_en = concatDynamicTag(item,'en')
  811. //数据列
  812. let nameCh:String = dynamic_arr.length > 1
  813. ? `${item.EdbAliasName||item.EdbName}(${item.SourceName})${dynamic_tag}`
  814. : `${item.EdbAliasName||item.EdbName}${dynamic_tag}`
  815. let nameEn:String=item.EdbNameEn?`${item.EdbNameEn}${dynamic_tag_en}`:''
  816. let name :String=language.value == 'zh'?nameCh:nameEn
  817. //预测指标配置
  818. let predict_params = item.EdbInfoCategoryType === 1 ? getPredictParams(item,chartStyle) : {};
  819. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  820. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  821. let obj = {
  822. data: [] as any[],
  823. type: chartInfo.ChartType!==3?(chartStyle || item.ChartStyle):ExtraConfig?.IsHeap==1?'area':((chartTheme && chartTheme.lineOptionList[lineIndex].lineType) || item.ChartStyle),
  824. yAxis: serie_yIndex,
  825. name,
  826. color: item.ChartColor,
  827. lineWidth: Number(item.ChartWidth)||(chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 1,
  828. fillColor: (chartInfo.ChartType === 3 || (chartInfo.ChartType === 6 && item.ChartStyle === 'areaspline')) ? item.ChartColor : undefined,
  829. zIndex: (chartInfo.ChartType === 6 && ['line','spline'].includes(item.ChartStyle)) ? 1 : 0, //防止组合图曲线被遮住
  830. borderWidth: 1,
  831. borderColor: item.ChartColor,
  832. ...predict_params,
  833. stacking:chartInfo.ChartType==6?DataResp.IsHeap!==1?undefined:'normal':chartInfo.ChartType==3&&ExtraConfig?.IsHeap==1?ExtraConfig?.HeapWay==1?'normal':'percent':undefined,
  834. threshold: chartInfo.ChartType==3?item.ChartScale?Number(item.ChartScale):0:null
  835. };
  836. item.DataList = item.DataList || []
  837. for (let i of item.DataList) {
  838. obj.data.push([i.DataTimestamp, i.Value]);
  839. }
  840. if(item.DataList.length){
  841. minTimeArr.push(item.DataList[0].DataTimestamp)
  842. maxTimeArr.push(item.DataList[item.DataList.length-1].DataTimestamp)
  843. }
  844. data.push(obj);
  845. ydata.push(yItem);
  846. })
  847. // 范围为1年内 x轴显示为月/日 否则默认年/月
  848. let xAxis:any = {};
  849. const isLessThanOneYear:boolean = xTimeDiffer();
  850. let minTime: number=Math.min(...minTimeArr);
  851. let maxTime=Math.max(...maxTimeArr);
  852. let step = setXaxisStep(maxTime-minTime);
  853. xAxis = {
  854. ...defaultOpts.xAxis,
  855. tickInterval: screen.value === 'phone' ? step : undefined,
  856. labels: {
  857. formatter: function (ctx: any) {
  858. return isLessThanOneYear
  859. ? Highcharts.dateFormat('%m/%d', ctx.value)
  860. : Highcharts.dateFormat('%y/%m', ctx.value);
  861. },
  862. style: {
  863. ...chartTheme&&chartTheme.xAxisOptions.style
  864. }
  865. },
  866. plotBands: setAxisPlotAreas(3,'datetime'),
  867. plotLines: setAxisPlotLines(3,'datetime')
  868. }
  869. let options={
  870. series: data,
  871. yAxis: ydata,
  872. xAxis
  873. }
  874. //面积图百分比tooltip
  875. if(chartInfo.ChartType===3&&ExtraConfig?.HeapWay == 2) {
  876. options.tooltip = {
  877. split: false,
  878. shared: true,
  879. dateTimeLabelFormats: {
  880. // 时间格式化字符
  881. day: '%Y/%m/%d',
  882. week: "%Y/%m",
  883. month: '%Y/%m',
  884. year: '%Y/%m',
  885. },
  886. xDateFormat:'%Y/%m/%d',
  887. className:'chart-tooltips-box',
  888. pointFormat: '<span style=\"color:{point.color}\">●</span><span>{series.name}</span>' +':<b>{point.percentage:.1f}%</b> ({point.y:,.1f})<br/>'
  889. }
  890. }
  891. return options;
  892. }
  893. /* 散点图 第一个指标值为x轴 第二个指标为y轴*/
  894. const setScatterChartOptions = () => {
  895. const { dataList,chartInfo } = state;
  896. /* 主题样式*/
  897. const chartTheme = state.chartInfo.ChartThemeStyle ? JSON.parse(state.chartInfo.ChartThemeStyle) : null;
  898. // 取2个指标中日期相同的数据
  899. const real_data: any[] = [];
  900. let tmpData_date: any = {};//用来取点对应的日期
  901. let data1 = _.cloneDeep(dataList)[0].DataList || [];
  902. let data2 = _.cloneDeep(dataList)[1].DataList || [];
  903. data1.forEach((_item: IParams) => {
  904. data2.forEach((_item2: IParams) => {
  905. if(_item.DataTimestamp === _item2.DataTimestamp) {
  906. //日期
  907. let itemIndex =_item.Value + "_" +_item2.Value
  908. if(tmpData_date[itemIndex]) {
  909. tmpData_date[itemIndex].push( moment(_item.DataTimestamp).format('YYYY/MM/DD'))
  910. } else {
  911. tmpData_date[itemIndex] = [moment(_item.DataTimestamp).format('YYYY/MM/DD')]
  912. }
  913. //值
  914. real_data.push({
  915. x: _item.Value,
  916. y: _item2.Value
  917. })
  918. }
  919. })
  920. })
  921. real_data.sort((x,y) => x-y);
  922. //悬浮窗 拼接日期 原始指标名称
  923. let tooltip = {
  924. formatter: function() {
  925. const that: any = this;
  926. return language.value=='zh'?
  927. `<strong>${ tmpData_date[that.x+'_'+that.y].length > 4 ? tmpData_date[that.x+'_'+that.y].slice(0,4).join()+'...' : tmpData_date[that.x+'_'+that.y].join() }</strong><br>
  928. ${dataList[0].EdbName}: <span style="font-weight: 600"> ${that.x}</span><br>
  929. ${dataList[1].EdbName}: <span style="font-weight: 600"> ${that.y}</span>
  930. `:
  931. `<strong>${ tmpData_date[that.x+'_'+that.y].length > 4 ? tmpData_date[that.x+'_'+that.y].slice(0,4).join()+'...' : tmpData_date[that.x+'_'+that.y].join() }</strong><br>
  932. ${dataList[0].EdbNameEn}: <span style="font-weight: 600"> ${that.x}</span><br>
  933. ${dataList[1].EdbNameEn}: <span style="font-weight: 600"> ${that.y}</span>
  934. `
  935. }
  936. }
  937. const { IsOrder,ChartColor } = dataList[0];
  938. const textYZh = dataList[1].ConvertUnit||dataList[1].Unit
  939. const textYEn = textYZh?dataList[1].ConvertEnUnit||dataList[1].UnitEn||dataList[1].ConvertUnit||dataList[1].Unit:''
  940. const textX = dataList[0].ConvertUnit||dataList[0].Unit
  941. const textXEn = textX?dataList[0].ConvertEnUnit||dataList[0].UnitEn||dataList[0].ConvertUnit||dataList[0].Unit:''
  942. //获取对应轴的上下限
  943. let minLimit = 0,maxLimit = 0
  944. minLimit = state.chartLimit.min||0
  945. maxLimit = state.chartLimit.max||0
  946. //y轴
  947. let yAxis = {
  948. title: {
  949. text: language.value=='zh'?`${textYZh}`:textYEn,
  950. // text: null,
  951. align: 'high',
  952. rotation: 0,
  953. y: -5,
  954. x:0,
  955. textAlign: 'left',
  956. reserveSpace: false,
  957. style:{
  958. ...chartTheme&&chartTheme.yAxisOptions.style
  959. },
  960. },
  961. labels: {
  962. formatter: function (ctx: any) {
  963. return ctx.value;
  964. },
  965. align: 'center',
  966. style:{
  967. ...chartTheme&&chartTheme.yAxisOptions.style
  968. },
  969. },
  970. opposite: false,
  971. reversed: IsOrder,
  972. min: Number(minLimit),
  973. max: Number(maxLimit),
  974. tickWidth: 1,
  975. tickLength: 5,
  976. lineWidth: 1,
  977. lineColor: '#bfbfbf',
  978. tickColor: '#bfbfbf',
  979. offset: 0,
  980. visible: true,
  981. gridLineWidth: 0,
  982. tickPosition: 'inside',
  983. endOnTick: false,
  984. startOnTick: false,
  985. showLastLabel: true,
  986. tickPixelInterval: 50,
  987. plotBands: setAxisPlotAreas(1),
  988. plotLines: setAxisPlotLines(1)
  989. }
  990. //数据列
  991. let series: any = {
  992. data: [],
  993. type: 'scatter',
  994. name: language.value == 'zh'?`${chartInfo.ChartName}${IsOrder ? '(逆序)' : ''}`:`${chartInfo.ChartNameEn}${IsOrder ? '(reserve)' : ''}`,
  995. color: ChartColor,
  996. chartType: 'linear',
  997. marker: {
  998. radius: (chartTheme&&chartTheme.lineOptionList[0].radius)||5,
  999. },
  1000. }
  1001. real_data.forEach(_ => {
  1002. series.data.push([_.x,_.y])
  1003. })
  1004. return {
  1005. title: {
  1006. text:''
  1007. },
  1008. series: [ series ],
  1009. yAxis,
  1010. xAxis: {
  1011. ...scatterXAxis,
  1012. title: {
  1013. text: language.value=='zh'?`${textX}`:textXEn,
  1014. align: 'high',
  1015. rotation: 0,
  1016. x: 0,
  1017. offset: 20,
  1018. style: {
  1019. ...chartTheme&&chartTheme.xAxisOptions.style
  1020. },
  1021. },
  1022. labels: {
  1023. style: {
  1024. ...chartTheme&&chartTheme.xAxisOptions.style
  1025. }
  1026. },
  1027. plotBands: setAxisPlotAreas(3),
  1028. plotLines: setAxisPlotLines(3)
  1029. },
  1030. tooltip
  1031. }
  1032. }
  1033. /* 奇怪柱状图
  1034. 获取图表详情后赋值奇怪柱状图数据 */
  1035. const barChartRenderData = ref<any>({})
  1036. const initBarData = (data: { XEdbIdValue: number[]; YDataList: any; EdbInfoList: any; ChartInfo: any; }) => {
  1037. const { XEdbIdValue,YDataList,EdbInfoList,ChartInfo } = data;
  1038. barChartRenderData.value = {
  1039. barDateList: YDataList,
  1040. barXIdData: XEdbIdValue,
  1041. barEdbData: EdbInfoList,
  1042. chartInfo: ChartInfo
  1043. }
  1044. state.chartLimit = {
  1045. min: Number(ChartInfo.LeftMin),
  1046. max: Number(ChartInfo.LeftMax),
  1047. }
  1048. return setBarChart()
  1049. }
  1050. const setBarChart = () => {
  1051. const {barDateList,barXIdData,barEdbData,chartInfo} = barChartRenderData.value;
  1052. const { chartLimit } = state;
  1053. let seriesData: { data: any; type: string; yAxis: number; name: any; color: any; chartType: string; }[] = [];
  1054. const data = _.cloneDeep(barDateList);
  1055. /* 主题样式*/
  1056. const chartTheme = chartInfo.ChartThemeStyle ? JSON.parse(chartInfo.ChartThemeStyle) : null;
  1057. let categories = language.value==='zh'
  1058. ? barXIdData.map((_:number) => barEdbData.find((edb: { EdbInfoId: number; }) => edb.EdbInfoId===_).EdbAliasName)
  1059. : barXIdData.map((_:number) => barEdbData.find((edb: { EdbInfoId: number; }) => edb.EdbInfoId===_).EdbNameEn)
  1060. //x轴
  1061. let xAxis = {
  1062. ...scatterXAxis,
  1063. categories,
  1064. tickWidth: 1,
  1065. labels: {
  1066. style: {
  1067. ...chartTheme&&chartTheme.xAxisOptions.style
  1068. }
  1069. }
  1070. }
  1071. const { max,min } = chartLimit;
  1072. console.log(max,min)
  1073. //y轴
  1074. let yAxis = {
  1075. ...basicYAxis,
  1076. title: {
  1077. text: language.value==='zh' ? chartInfo.Unit : (chartInfo.UnitEn||chartInfo.Unit),
  1078. align: 'high',
  1079. rotation: 0,
  1080. y: -12,
  1081. x:0,
  1082. textAlign: 'left',
  1083. reserveSpace: false,
  1084. style:{
  1085. ...chartTheme&&chartTheme.yAxisOptions.style
  1086. },
  1087. },
  1088. labels: {
  1089. formatter: function (ctx:any) {
  1090. let val = ctx.value;
  1091. return val;
  1092. },
  1093. align: 'center',
  1094. style:{
  1095. ...chartTheme&&chartTheme.yAxisOptions.style
  1096. },
  1097. },
  1098. min: Number(min),
  1099. max: Number(max),
  1100. opposite: false,
  1101. tickWidth: 1,
  1102. plotBands: setAxisPlotAreas(1),
  1103. plotLines: setAxisPlotLines(1)
  1104. }
  1105. //数据列
  1106. data.forEach((item: { Value: number; Name: string; Date: string; Color: string; }) => {
  1107. let serie_item = {
  1108. data: item.Value,
  1109. type: 'column',
  1110. yAxis: 0,
  1111. name: language.value==='zh' ? (item.Name || item.Date) : item.Date,
  1112. color: item.Color,
  1113. chartType: 'linear'
  1114. };
  1115. seriesData.push(serie_item)
  1116. })
  1117. return {
  1118. title: {
  1119. text:''
  1120. },
  1121. plotOptions: {
  1122. column:{
  1123. stacking: null,
  1124. },
  1125. },
  1126. series: seriesData,
  1127. yAxis: [ yAxis ],
  1128. xAxis
  1129. }
  1130. }
  1131. /* 散点截面图 */
  1132. const sectionScatterRenderData = ref<any>({});
  1133. const initSectionScatterData = (data: { DataResp:any,EdbInfoList:any[] }) => {
  1134. sectionScatterRenderData.value = data.DataResp;
  1135. state.chartLimit.min=Number(data.DataResp.YMinValue)
  1136. state.chartLimit.max=Number(data.DataResp.YMaxValue)
  1137. state.chartLimit.x_min=Number(data.DataResp.XMinValue)
  1138. state.chartLimit.x_max=Number(data.DataResp.XMaxValue)
  1139. //校验英文名称是否完整
  1140. // if(routeQuery.value.fromPage === 'en' && language.value==='en') {
  1141. // const { XNameEn,XUnitNameEn,YNameEn,YUnitNameEn } = data.DataResp;
  1142. // // DataList可能是null
  1143. // const DataList = data.DataResp.DataList||[]
  1144. // let isAllEn = true;
  1145. // if(!XNameEn || !XUnitNameEn || !YNameEn || !YUnitNameEn) isAllEn = false;
  1146. // if(DataList.some(_ => !_.NameEn)) isAllEn = false;
  1147. // console.log(isAllEn)
  1148. // language.value = isAllEn ? 'en' : 'zh';
  1149. // }
  1150. return setSectionScatterChart()
  1151. }
  1152. /* 截面散点图设置 sectionScatterData */
  1153. const setSectionScatterChart = () => {
  1154. const { chartLimit } = state;
  1155. const { DataList,XName,XNameEn,YName,YNameEn } = sectionScatterRenderData.value;
  1156. /* 主题样式*/
  1157. const chartTheme = state.chartInfo.ChartThemeStyle ? JSON.parse(state.chartInfo.ChartThemeStyle) : null;
  1158. if(!DataList){
  1159. return
  1160. }
  1161. const { min,max,x_min,x_max } = chartLimit;
  1162. //y轴
  1163. let yAxis = {
  1164. ...basicYAxis,
  1165. title: {
  1166. text: language.value === 'zh' ? YName : YNameEn,
  1167. align: 'middle',
  1168. style:{
  1169. ...chartTheme&&chartTheme.yAxisOptions.style
  1170. },
  1171. },
  1172. labels: {
  1173. style:{
  1174. ...chartTheme&&chartTheme.yAxisOptions.style
  1175. },
  1176. },
  1177. opposite: false,
  1178. reversed: false,
  1179. min: Number(min),
  1180. max: Number(max),
  1181. tickWidth: 1,
  1182. plotBands: setAxisPlotAreas(1),
  1183. plotLines: setAxisPlotLines(1)
  1184. }
  1185. //x轴
  1186. let xAxis = {
  1187. ...scatterXAxis,
  1188. title: {
  1189. text: language.value === 'zh' ? XName : XNameEn,
  1190. align: 'middle',
  1191. style: {
  1192. ...chartTheme&&chartTheme.xAxisOptions.style
  1193. },
  1194. },
  1195. labels: {
  1196. style:{
  1197. ...chartTheme&&chartTheme.xAxisOptions.style
  1198. },
  1199. },
  1200. min: Number(x_min),
  1201. max: Number(x_max),
  1202. plotBands: setAxisPlotAreas(3),
  1203. plotLines: setAxisPlotLines(3)
  1204. }
  1205. //数据列
  1206. let series: any[] = [];
  1207. DataList.forEach((item:any,index:number) => {
  1208. // 图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  1209. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  1210. //数据列
  1211. let series_item = {
  1212. data: [] as any[],
  1213. type: 'scatter',
  1214. name: language.value === 'zh' ? item.Name : item.NameEn,
  1215. color: item.Color,
  1216. lineWidth: 0,
  1217. chartType: 'linear',
  1218. zIndex:1,
  1219. marker: {
  1220. radius: (chartTheme&&chartTheme.lineOptionList[lineIndex].radius)||5,
  1221. },
  1222. visible: true
  1223. }
  1224. item.EdbInfoList.forEach(_ => {
  1225. series_item.data.push({
  1226. x: _.XValue,
  1227. y: _.YValue,
  1228. dataLabels: {
  1229. enabled: _.IsShow,
  1230. allowOverlap: true,
  1231. align: 'left',
  1232. format: language.value === 'zh' ? _.Name : _.NameEn
  1233. }
  1234. })
  1235. })
  1236. series.push(series_item);
  1237. //趋势线
  1238. if(item.ShowTrendLine) {
  1239. let trend_data = item.TrendLimitData.map((_,_index) => (
  1240. _index === item.TrendLimitData.length-1 ? {
  1241. x: _.X,
  1242. y: _.Y,
  1243. dataLabels: {
  1244. enabled: item.ShowRSquare || item.ShowFitEquation,
  1245. align: 'left',
  1246. color: '#666',
  1247. x: 20,
  1248. y: 30,
  1249. zIndex: 9,
  1250. allowOverlap: true,
  1251. formatter: function(){
  1252. let tag = '';
  1253. item.ShowRSquare && item.ShowFitEquation
  1254. ? tag =`<span>${item.TrendLine}</span><br><span>R²=${item.RSquare}</span>`
  1255. : item.ShowRSquare && !item.ShowFitEquation
  1256. ? tag =`<span>R²=${item.RSquare}</span>`
  1257. : item.ShowFitEquation && !item.ShowRSquare
  1258. ? tag =`<span>${item.TrendLine}</span>`
  1259. : ''
  1260. return tag
  1261. }
  1262. }
  1263. } : {
  1264. x: _.X,
  1265. y: _.Y,
  1266. }
  1267. ))
  1268. let trend_item = {
  1269. data: trend_data,
  1270. type: 'spline',
  1271. linkedTo: ':previous',
  1272. color: item.Color,
  1273. lineWidth: 1,
  1274. chartType: 'linear',
  1275. enableMouseTracking: false,
  1276. dashStyle:'Dash',
  1277. zIndex: 2,
  1278. visible: true,
  1279. marker: {
  1280. enabled: false
  1281. }
  1282. }
  1283. series.push(trend_item)
  1284. }
  1285. })
  1286. let tooltip = {
  1287. formatter: function() {
  1288. const that:any = this;
  1289. let str = '';
  1290. if(language.value === 'zh') {
  1291. let series_obj = DataList.find(_ => _.Name === that.series.name);
  1292. let ponit_obj = series_obj.EdbInfoList.find(_ => _.XValue ===that.x && _.YValue===that.y);
  1293. str=`<b>${ ponit_obj.Name }</b>`;
  1294. str += `<br><span style="color:${that.color}">\u25CF</span>${ponit_obj.XName}: ${that.x} ${ponit_obj.XDate}<br>`;
  1295. str += `<span style="color:${that.color}">\u25CF</span>${ponit_obj.YName}: ${that.y} ${ponit_obj.YDate}`;
  1296. }else {
  1297. let series_obj = DataList.find(_ => _.NameEn === that.series.name);
  1298. let ponit_obj = series_obj.EdbInfoList.find(_ => _.XValue ===that.x && _.YValue===that.y);
  1299. str=`<b>${ ponit_obj.NameEn }</b>`;
  1300. str += `<br><span style="color:${that.color}">\u25CF</span>${ponit_obj.XNameEn}: ${that.x} ${ponit_obj.XDate}<br>`;
  1301. str += `<span style="color:${that.color}">\u25CF</span>${ponit_obj.YNameEn}: ${that.y} ${ponit_obj.YDate}`;
  1302. }
  1303. return str
  1304. }
  1305. }
  1306. return {
  1307. title: {
  1308. text:''
  1309. },
  1310. series,
  1311. yAxis: [yAxis],
  1312. xAxis,
  1313. tooltip
  1314. }
  1315. }
  1316. /* 商品价格曲线/利润曲线
  1317. */
  1318. const commodityChartRenderData = ref<any>({})
  1319. const initCommodityData = (data: { XDataList: any[]; YDataList: any; EdbInfoList: any; ChartInfo: any; DataResp?:any }) => {
  1320. const { XDataList,YDataList,EdbInfoList,ChartInfo,DataResp } = data;
  1321. commodityChartRenderData.value = {
  1322. commodityEdbList: EdbInfoList,
  1323. commodityChartData: ChartInfo.Source===5?DataResp.YDataList:YDataList,
  1324. commodityXData: ChartInfo.Source===5?DataResp.XDataList:XDataList
  1325. }
  1326. if(ChartInfo.Source===5) {
  1327. state.chartInfo = {
  1328. ...state.chartInfo,
  1329. ProfitName: DataResp.ProfitName,
  1330. ProfitNameEn: DataResp.ProfitNameEn
  1331. }
  1332. }
  1333. state.chartLimit = {
  1334. min: Number(ChartInfo.LeftMin),
  1335. max: Number(ChartInfo.LeftMax)
  1336. }
  1337. return setCommodityChart();
  1338. }
  1339. /* 商品价格曲线设置 绘图逻辑同奇怪柱形图*/
  1340. const setCommodityChart = () => {
  1341. const {chartLimit,chartInfo} = state;
  1342. const { commodityChartData,commodityXData,commodityEdbList } = commodityChartRenderData.value;
  1343. let seriesData:any[] = [];
  1344. const data = _.cloneDeep(commodityChartData);
  1345. /* 主题样式*/
  1346. const chartTheme = chartInfo.ChartThemeStyle ? JSON.parse(chartInfo.ChartThemeStyle) : null;
  1347. //x轴
  1348. let xAxis = {
  1349. ...scatterXAxis,
  1350. categories: commodityXData.filter(_=>_.IsHide===0).map(_ => language.value === 'zh' ? _.Name:_.NameEn),
  1351. tickWidth: 1,
  1352. labels: {
  1353. style: {
  1354. ...chartTheme&&chartTheme.xAxisOptions.style
  1355. }
  1356. }
  1357. }
  1358. const { max,min } = chartLimit;
  1359. //y轴
  1360. let yAxis = {
  1361. ...basicYAxis,
  1362. title: {
  1363. text: language.value === 'zh' ? commodityEdbList[0].Unit : commodityEdbList[0].UnitEn,
  1364. align: 'high',
  1365. rotation: 0,
  1366. y: -12,
  1367. textAlign: 'left',
  1368. reserveSpace: false,
  1369. style:{
  1370. ...chartTheme&&chartTheme.yAxisOptions.style
  1371. },
  1372. },
  1373. labels: {
  1374. formatter: function (ctx:any) {
  1375. let val = ctx.value;
  1376. return val;
  1377. },
  1378. align: 'center',
  1379. style:{
  1380. ...chartTheme&&chartTheme.yAxisOptions.style
  1381. },
  1382. },
  1383. min: Number(min),
  1384. max: Number(max),
  1385. opposite: false,
  1386. tickWidth: 1,
  1387. }
  1388. //数据列
  1389. data.forEach((item: { Value: number[]; Name: string; Date: string; Color: string;NameEn: string,XEdbInfoIdList: number[],NoDataEdbList: number[] },index:number) => {
  1390. //处理首或/尾全是无效数据的以null填充
  1391. let filterData = filterInvalidData(item)
  1392. // 图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  1393. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  1394. let serie_item = {
  1395. data: filterData,
  1396. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || 'spline',
  1397. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  1398. yAxis: 0,
  1399. name: language.value === 'zh' ? item.Name : item.NameEn,
  1400. color: item.Color,
  1401. chartType: 'linear',
  1402. lineWidth: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 3,
  1403. marker: {
  1404. enabled: false
  1405. }
  1406. };
  1407. seriesData.push(serie_item)
  1408. })
  1409. //tooltip
  1410. let tooltip = {
  1411. formatter: function() {
  1412. const ctx: any = this;
  1413. let str: string = '';
  1414. if(language.value === 'zh') {
  1415. ctx.points.forEach((item: { series:{name: string},y: number,color: string }) => {
  1416. let obj_item = data.find((_:any) => _.Name === item.series.name);
  1417. let index = commodityXData.findIndex(_ => _.Name === ctx.x);
  1418. //合约显示
  1419. let haveContract = obj_item.XEdbInfoIdList[index];
  1420. if(haveContract) {
  1421. // 利润曲线指标名
  1422. const isEdb=commodityEdbList.some(_=>_.EdbInfoId===haveContract)
  1423. let edb_name = chartInfo.Source === 5
  1424. ? (isEdb? obj_item.NameList[index] : `${chartInfo.ProfitName}(${obj_item.NameList[index]})`)
  1425. : commodityEdbList.find(_ => _.EdbInfoId === obj_item.XEdbInfoIdList[index]).EdbName;
  1426. str+=`<b>${ edb_name }</b>`
  1427. if(!obj_item.NoDataEdbList.includes(obj_item.XEdbInfoIdList[index])) {
  1428. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: ${item.y}<br>`
  1429. }else {
  1430. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: 无<br>`
  1431. }
  1432. }
  1433. })
  1434. }else {
  1435. ctx.points.forEach((item: { series:{name: string},y: number,color: string }) => {
  1436. let obj_item = data.find((_: any) => _.NameEn === item.series.name);
  1437. let index = commodityXData.findIndex(_ => _.NameEn === ctx.x);
  1438. let haveContract = obj_item.XEdbInfoIdList[index];
  1439. if(haveContract) {
  1440. const isEdb=commodityEdbList.some(_=>_.EdbInfoId===haveContract)
  1441. let edb_name = chartInfo.Source === 5
  1442. ? (isEdb? obj_item.NameList[index] : `${chartInfo.ProfitNameEn}(${obj_item.NameList[index]})`)
  1443. : commodityEdbList.find(_ => _.EdbInfoId === obj_item.XEdbInfoIdList[index]).EdbNameEn;
  1444. str+=`<b>${ edb_name }</b>`
  1445. if(!obj_item.NoDataEdbList.includes(obj_item.XEdbInfoIdList[index])) {
  1446. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: ${item.y}<br>`
  1447. }else {
  1448. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: 无<br>`
  1449. }
  1450. }
  1451. })
  1452. }
  1453. return str || '无合约'
  1454. },
  1455. shared: true
  1456. }
  1457. return {
  1458. title: {
  1459. text:''
  1460. },
  1461. series: seriesData,
  1462. yAxis: [ yAxis ],
  1463. xAxis,
  1464. tooltip
  1465. }
  1466. };
  1467. /* 处理无效数据为null */
  1468. const filterInvalidData = (item:{ Value: number[]; Name: string; Date: string; Color: string;NameEn: string,XEdbInfoIdList: number[],NoDataEdbList: number[] })=> {
  1469. let validateArr = item.XEdbInfoIdList.filter(_ => _&&!item.NoDataEdbList.includes(_));
  1470. let first_index = item.XEdbInfoIdList.findIndex(_ => _ === validateArr[0]);
  1471. let last_index = item.XEdbInfoIdList.findIndex(_ => _ === validateArr[validateArr.length-1]);
  1472. console.log('first_index',first_index)
  1473. console.log('last_index',last_index)
  1474. let arr = item.Value.map((item,index:number) => {
  1475. if(index < first_index || index > last_index) {
  1476. return null
  1477. }else {
  1478. return item
  1479. }
  1480. })
  1481. // 根据设置的x轴显示隐藏去除值
  1482. let temArr=[]
  1483. commodityChartRenderData.value.commodityXData.forEach((i,index)=>{
  1484. if(i.IsHide!==1){
  1485. temArr.push(arr[index])
  1486. }
  1487. })
  1488. return temArr;
  1489. }
  1490. /* 相关性图表 */
  1491. const initRelevanceChartData=(data)=>{
  1492. /* 主题样式*/
  1493. const chartTheme = state.chartInfo.ChartThemeStyle ? JSON.parse(state.chartInfo.ChartThemeStyle) : null;
  1494. const relevanceUnitEnMap={
  1495. '年': 'Year',
  1496. '季': 'Season',
  1497. '月': 'Month',
  1498. '周': 'Week',
  1499. '天': 'Day',
  1500. }
  1501. // 处理X轴
  1502. let xAxis={
  1503. categories: data.ChartInfo.Source===3 ? data.XEdbIdValue : data.DataResp.XDateTimeValue,
  1504. tickWidth: 1,
  1505. title: {
  1506. text: data.ChartInfo.Source===3 ? (language.value=='zh'?`期数(${data.CorrelationChartInfo.LeadUnit})`:`stage(${relevanceUnitEnMap[data.CorrelationChartInfo.LeadUnit]})`):null,
  1507. align: 'high',
  1508. rotation: 0,
  1509. style: {
  1510. ...chartTheme&&chartTheme.xAxisOptions.style
  1511. }
  1512. },
  1513. labels: {
  1514. style: {
  1515. ...chartTheme&&chartTheme.xAxisOptions.style
  1516. }
  1517. },
  1518. tickInterval: 1,
  1519. offset:0,
  1520. tickmarkPlacement:'on'
  1521. }
  1522. // 处理Y轴
  1523. let yAxis={
  1524. ...basicYAxis,
  1525. title: {
  1526. text: language.value=='zh'?'相关性系数':'Correlation coefficient',
  1527. align: 'high',
  1528. rotation: 0,
  1529. y: -12,
  1530. textAlign: 'left',
  1531. reserveSpace: false,
  1532. style:{
  1533. ...chartTheme&&chartTheme.yAxisOptions.style
  1534. },
  1535. },
  1536. labels: {
  1537. formatter: function (ctx) {
  1538. let val = ctx.value;
  1539. return val;
  1540. },
  1541. align: 'center',
  1542. style:{
  1543. ...chartTheme&&chartTheme.yAxisOptions.style
  1544. },
  1545. },
  1546. opposite: false,
  1547. tickWidth: 1,
  1548. }
  1549. //处理series
  1550. let seriesData:any[]=[]
  1551. data.YDataList.forEach((item:any,index:number)=>{
  1552. // 图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  1553. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  1554. let serie_item = {
  1555. data: item.Value,
  1556. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || 'spline',
  1557. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  1558. yAxis: 0,
  1559. name: language.value=='zh'?item.Name:item.NameEn||item.Name,
  1560. color: item.Color,
  1561. chartType: 'linear',
  1562. lineWidth: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 3,
  1563. marker: {
  1564. enabled: false
  1565. }
  1566. };
  1567. seriesData.push(serie_item)
  1568. })
  1569. const { LeadValue,LeadUnit } = data.CorrelationChartInfo;
  1570. let tooltip = {
  1571. formatter: function() {
  1572. const that:any = this;
  1573. let str='';
  1574. if(language.value=='zh'){
  1575. str = `<p>相关性系数:${that.y.toFixed(4)}</p><br><p>领先${ data.ChartInfo.Source===3 ?that.x+'期' : LeadValue+LeadUnit}</p>`
  1576. }else{
  1577. str = `<p>Correlation coefficient:${that.y.toFixed(4)}</p><br><p>lead${ data.ChartInfo.Source===3 ? that.x+'stage' : LeadValue+relevanceUnitEnMap[LeadUnit]}</p>`
  1578. }
  1579. return str
  1580. },
  1581. }
  1582. return {
  1583. isRelevanceChart:data.ChartInfo.Source===3,
  1584. title: {
  1585. text:'',
  1586. },
  1587. series: seriesData,
  1588. yAxis: [yAxis] ,
  1589. xAxis:xAxis,
  1590. tooltip
  1591. }
  1592. }
  1593. /* 统计特征
  1594. 标准差
  1595. 百分比
  1596. 频率
  1597. 滚动相关性*/
  1598. const statisticFrequencyRenderData = ref<any>({});
  1599. const initStatisticChartData = (data: { DataResp:any,ChartInfo:any,CorrelationChartInfo:any }) => {
  1600. if(data.ChartInfo.Source === 9) { //频率图
  1601. statisticFrequencyRenderData.value = data.DataResp;
  1602. return setStatisticFrequency();
  1603. }else {
  1604. state.dataList = [data.DataResp];
  1605. if(data.ChartInfo.Source === 4) statisticFrequencyRenderData.value = data.CorrelationChartInfo;
  1606. return setDefaultLineOptions();
  1607. }
  1608. }
  1609. /* 统计频率图 */
  1610. const setStatisticFrequency = () => {
  1611. const { DataList,LeftMaxValue,LeftMinValue,RightMaxValue,RightMinValue } = statisticFrequencyRenderData.value
  1612. if(!DataList){
  1613. return
  1614. }
  1615. /* 主题样式*/
  1616. const chartTheme = state.chartInfo.ChartThemeStyle ? JSON.parse(state.chartInfo.ChartThemeStyle) : null;
  1617. let xAxis = {
  1618. ...scatterXAxis,
  1619. tickWidth: 1,
  1620. labels: {
  1621. style: {
  1622. ...chartTheme&&chartTheme.xAxisOptions.style
  1623. }
  1624. }
  1625. }
  1626. //y和系列
  1627. let yAxis:any[] = [],series:any[] = [];
  1628. DataList.forEach((item,index) => {
  1629. let y_item = {
  1630. ...basicYAxis,
  1631. title: {
  1632. text: language.value === 'zh' ? item.Unit : item.UnitEn,
  1633. align: 'high',
  1634. rotation: 0,
  1635. y: -12,
  1636. reserveSpace: false,
  1637. style:{
  1638. ...chartTheme&&chartTheme.yAxisOptions.style
  1639. },
  1640. },
  1641. labels: {
  1642. style:{
  1643. ...chartTheme&&chartTheme.yAxisOptions.style
  1644. },
  1645. },
  1646. opposite: item.IsAxis===1?false:true,
  1647. min: index===0? Number(LeftMinValue):Number(RightMinValue),
  1648. max: index===0? Number(LeftMaxValue):Number(RightMaxValue),
  1649. tickWidth: 1,
  1650. }
  1651. // 图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  1652. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  1653. let series_item = {
  1654. data: item.Value.map(_ =>[_.X,_.Y]),
  1655. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  1656. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || 'spline',
  1657. yAxis: index,
  1658. name: language.value === 'zh' ? item.Name : item.NameEn,
  1659. color: item.Color,
  1660. lineWidth: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth)||3,
  1661. chartType: 'linear',
  1662. zIndex:1
  1663. }
  1664. series.push(series_item);
  1665. yAxis.push(y_item)
  1666. })
  1667. let tooltip = {
  1668. formatter: function() {
  1669. let that:any = this;
  1670. let xList = DataList[0].Value.map(_ =>_.X);
  1671. let step = xList[1]-xList[0];
  1672. let data_interval = `[${Number(that.x).toFixed(2)},${Number(that.x+step).toFixed(2)}]`;
  1673. let str=`<b>${ data_interval }</b>`;
  1674. that.points.forEach(item => {
  1675. str += `<br><span style="color:${item.color}">\u25CF</span>${item.series.name}: ${item.y}%`
  1676. })
  1677. return str
  1678. },
  1679. shared: true
  1680. }
  1681. return {
  1682. title: {
  1683. text:''
  1684. },
  1685. tooltip,
  1686. series,
  1687. yAxis,
  1688. xAxis
  1689. }
  1690. }
  1691. /* 拟合方程曲线 曲线图绘图逻辑*/
  1692. const initFittingEquation = (data) => {
  1693. state.dataList = [data.DataResp];
  1694. return setDefaultLineOptions();
  1695. }
  1696. /* 跨品种分析 */
  1697. const crossVarietyChartRenderData = ref<any>({})
  1698. const initCrossVarietyChartData = (data:{ DataResp:any,ChartInfo:any,EdbInfoList:any }) => {
  1699. state.dataList = data.EdbInfoList;
  1700. crossVarietyChartRenderData.value = data.DataResp;
  1701. /* 历史数据chartInfo里全是空 兼容下历史数据不崩 */
  1702. state.chartLimit.min=data.ChartInfo.LeftMin?Number(data.ChartInfo.LeftMin):Number(data.DataResp.YMinValue)
  1703. state.chartLimit.max=data.ChartInfo.LeftMax?Number(data.ChartInfo.LeftMax):Number(data.DataResp.YMaxValue)
  1704. state.chartLimit.x_min=data.ChartInfo.XMin?Number(data.ChartInfo.XMin):Number(data.DataResp.XMinValue)
  1705. state.chartLimit.x_max=data.ChartInfo.XMax?Number(data.ChartInfo.XMax):Number(data.DataResp.XMaxValue)
  1706. //二次校验英文配置是否完整
  1707. // if(routeQuery.value.fromPage === 'en' && language.value==='en') {
  1708. // const { XNameEn,YNameEn,DataList } = data.DataResp;
  1709. // let isAllEn = true;
  1710. // let haveOneNoEn = DataList.some(_ => !_.NameEn);
  1711. // if(!XNameEn || !YNameEn || haveOneNoEn) isAllEn = false;
  1712. // language.value = isAllEn ? 'en' : 'zh';
  1713. // }
  1714. return setCrossVarietyChart()
  1715. }
  1716. /* 跨品种分析 */
  1717. const setCrossVarietyChart = () => {
  1718. const { chartLimit,dataList,chartInfo } = state;
  1719. /* 主题样式*/
  1720. const chartTheme = chartInfo.ChartThemeStyle ? JSON.parse(chartInfo.ChartThemeStyle) : null;
  1721. const { min,max,x_min,x_max } = chartLimit;
  1722. const { DataList,XName,YName,XNameEn,YNameEn } = crossVarietyChartRenderData.value;
  1723. //y轴
  1724. let yAxis = {
  1725. ...basicYAxis,
  1726. title: {
  1727. text: language.value === 'zh' ? YName : YNameEn,
  1728. align: 'middle',
  1729. style: {
  1730. ...chartTheme&&chartTheme.xAxisOptions.style
  1731. }
  1732. },
  1733. labels: {
  1734. style: {
  1735. ...chartTheme&&chartTheme.xAxisOptions.style
  1736. }
  1737. },
  1738. opposite: false,
  1739. reversed: false,
  1740. min: Number(min),
  1741. max: Number(max),
  1742. tickWidth: 1,
  1743. }
  1744. // x轴
  1745. let xAxis = {
  1746. ...scatterXAxis,
  1747. title: {
  1748. text: language.value === 'zh' ? XName : XNameEn,
  1749. align: 'middle',
  1750. style: {
  1751. ...chartTheme&&chartTheme.xAxisOptions.style
  1752. }
  1753. },
  1754. labels: {
  1755. style: {
  1756. ...chartTheme&&chartTheme.xAxisOptions.style
  1757. }
  1758. },
  1759. min: Number(x_min),
  1760. max: Number(x_max),
  1761. }
  1762. //数据列
  1763. let series:any[] = [];
  1764. const tagMap = { //标签对应文字
  1765. 1: '最新',
  1766. 3: 'Fix'
  1767. }
  1768. DataList.forEach(item => {
  1769. //数据列
  1770. let series_item = {
  1771. data: [] as any[],
  1772. type: 'scatter',
  1773. name: language.value === 'zh' ? item.Name : item.NameEn,
  1774. color: item.Color,
  1775. lineWidth: 0,
  1776. chartType: 'linear',
  1777. zIndex:1
  1778. }
  1779. item.CoordinatePointData.forEach(_ => {
  1780. series_item.data.push({
  1781. x: _.X,
  1782. y: _.Y,
  1783. dataLabels: {
  1784. enabled: _.ShowTips===1,
  1785. allowOverlap: true,
  1786. align: 'left',
  1787. format: tagMap[_.DateType] || `-${_.DaysAgo}D`,
  1788. }
  1789. })
  1790. })
  1791. series.push(series_item);
  1792. })
  1793. let tooltip = {
  1794. formatter: function() {
  1795. let that:any = this;
  1796. let str = '';
  1797. if(language.value === 'zh') {
  1798. let series_obj = DataList.find(_ => _.Name === that.series.name);
  1799. let ponit_obj = series_obj.CoordinatePointData.find(_ => _.X ===that.x && _.Y===that.y);
  1800. let xEdbInfo = dataList.find(_ => _.EdbInfoId===ponit_obj.XEdbInfoId);
  1801. let yEdbInfo = dataList.find(_ => _.EdbInfoId===ponit_obj.YEdbInfoId);
  1802. str=`<b>${ that.series.name }</b>`;
  1803. str += `<br><span style="color:${that.color}">\u25CF</span>${xEdbInfo.EdbName}: ${that.x} ${ponit_obj.XDate}<br>`;
  1804. str += `<span style="color:${that.color}">\u25CF</span>${yEdbInfo.EdbName}: ${that.y} ${ponit_obj.YDate}`;
  1805. }else {
  1806. let series_obj = DataList.find(_ => _.NameEn === that.series.name);
  1807. let ponit_obj = series_obj.CoordinatePointData.find(_ => _.X ===that.x && _.Y===that.y);
  1808. let xEdbInfo = dataList.find(_ => _.EdbInfoId===ponit_obj.XEdbInfoId);
  1809. let yEdbInfo = dataList.find(_ => _.EdbInfoId===ponit_obj.YEdbInfoId);
  1810. str=`<b>${ that.series.name }</b>`;
  1811. str += `<br><span style="color:${that.color}">\u25CF</span>${xEdbInfo.EdbNameEn}: ${that.x} ${ponit_obj.XDate}<br>`;
  1812. str += `<span style="color:${that.color}">\u25CF</span>${yEdbInfo.EdbNameEn}: ${that.y} ${ponit_obj.YDate}`;
  1813. }
  1814. return str
  1815. }
  1816. }
  1817. return {
  1818. title: {
  1819. text:''
  1820. },
  1821. series,
  1822. yAxis: [yAxis],
  1823. xAxis,
  1824. tooltip
  1825. }
  1826. }
  1827. /* 雷达图 */
  1828. const radarChartRenderData = ref<any>({})
  1829. const initRadarData = (data) => {
  1830. const { DataResp,EdbInfoList,ChartInfo } = data;
  1831. radarChartRenderData.value = {
  1832. YDataList: DataResp.YDataList,
  1833. XDataList: EdbInfoList.filter(_ => DataResp.XEdbIdValue.includes(_.EdbInfoId))
  1834. }
  1835. state.chartLimit.min=Number(ChartInfo.LeftMin)
  1836. state.chartLimit.max=Number(ChartInfo.LeftMax)
  1837. return setRadarChart();
  1838. }
  1839. const setRadarChart = () => {
  1840. const { YDataList,XDataList } = radarChartRenderData.value;
  1841. const { chartLimit,dataList,chartInfo } = state;
  1842. /* 主题样式*/
  1843. const chartTheme = chartInfo.ChartThemeStyle ? JSON.parse(chartInfo.ChartThemeStyle) : null;
  1844. let categories = language.value==='zh'
  1845. ? XDataList.map(_ => _.EdbAliasName||_.EdbName)
  1846. : XDataList.map(_ => _.EdbNameEn)
  1847. //x轴
  1848. let xAxis = {
  1849. lineWidth: 0,
  1850. tickLength: 0,
  1851. tickmarkPlacement: 'on',
  1852. categories,
  1853. labels: {
  1854. allowOverlap: true,
  1855. // align:'center',
  1856. distance: 20,
  1857. style: {
  1858. ...chartTheme&&chartTheme.xAxisOptions.style
  1859. }
  1860. }
  1861. }
  1862. //y轴
  1863. const { max,min } = chartLimit;
  1864. let yAxis = [{
  1865. gridLineInterpolation: 'polygon',
  1866. gridLineWidth: 1,
  1867. lineWidth: 0,
  1868. endOnTick: false,
  1869. startOnTick: false,
  1870. showLastLabel: true,
  1871. // tickAmount:4,
  1872. title: {
  1873. text: language.value==='zh' ? chartInfo.Unit : chartInfo.UnitEn,
  1874. align: 'high',
  1875. rotation: 0,
  1876. y: 5,
  1877. x:10,
  1878. textAlign: 'left',
  1879. reserveSpace: false,
  1880. style:{
  1881. ...chartTheme&&chartTheme.yAxisOptions.style
  1882. },
  1883. },
  1884. labels: {
  1885. allowOverlap: true,
  1886. style:{
  1887. ...chartTheme&&chartTheme.yAxisOptions.style
  1888. }
  1889. },
  1890. min: Number(min),
  1891. max: Number(max),
  1892. }]
  1893. //系列
  1894. let series:any[] = [];
  1895. YDataList.forEach((item,index) => {
  1896. // 图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  1897. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  1898. let serie_item = {
  1899. data: item.Value,
  1900. pointPlacement: 'on',
  1901. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || 'line',
  1902. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  1903. yAxis: 0,
  1904. name: language.value==='zh' ? (item.Name || item.Date) : item.Date,
  1905. color: item.Color,
  1906. lineWidth: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 1,
  1907. chartType: 'linear'
  1908. };
  1909. series.push(serie_item)
  1910. })
  1911. return {
  1912. chart: {
  1913. ...defaultOpts.chart,
  1914. ...chartTheme.drawOption,
  1915. spacing: [2,10,2,10],
  1916. polar:true,
  1917. },
  1918. title: {
  1919. text:''
  1920. },
  1921. pane: {
  1922. size: '80%'
  1923. },
  1924. series,
  1925. yAxis,
  1926. xAxis
  1927. }
  1928. }
  1929. //区间分析
  1930. const initIntervalAnalysisChartData=(data)=>{
  1931. console.log('初始化区间分析数据');
  1932. state.dataList=data.EdbInfoList
  1933. setLimitData(state.dataList,data)
  1934. return setDefaultLineOptions()
  1935. }
  1936. // 曲线图x轴显示计算年限差 >1年 显示年/月 <=1 显示月/日
  1937. const xTimeDiffer = () => {
  1938. const end_date = state.chartInfo.DateType === 5
  1939. ? state.chartInfo.EndDate
  1940. : state.chartInfo.DateType === 6
  1941. ? new Date()
  1942. : '';
  1943. //年限差
  1944. const year_differ = moment(end_date).diff(
  1945. moment(state.chartInfo.StartDate),
  1946. 'years',
  1947. true
  1948. );
  1949. // console.log(year_differ)
  1950. if ([5, 6].includes(state.chartInfo.DateType) && year_differ <= 1) {
  1951. return true
  1952. } else {
  1953. return false
  1954. }
  1955. }
  1956. /* 设置x轴步长 刻度数量多一点 */
  1957. const setXaxisStep = (timestamp: number) => {
  1958. return timestamp / 6;
  1959. }
  1960. /* 指标顺序调整 IsAxis: 0右轴 1左轴 2右2*/
  1961. const changeEdbOrder = (data: any[]) => {
  1962. // 左轴指标
  1963. let left_edbs = data.filter(_ => _.IsAxis===1);
  1964. //右轴指标
  1965. let right_edbs = data.filter(_ => !_.IsAxis);
  1966. // 右2轴指标
  1967. let right_two_edbs = data.filter(_ => _.IsAxis === 2);
  1968. // 按 左 右 右2顺序排列
  1969. return [left_edbs,right_edbs,right_two_edbs].flat(Infinity);
  1970. }
  1971. /* 拼接动态的指标名称小标签 */
  1972. const concatDynamicTag = (
  1973. { IsAxis, IsOrder, EdbInfoType, LeadValue, LeadUnit }: IDataProps,
  1974. lang: String = 'zh'
  1975. ): string => {
  1976. // IsAxis左轴1 右轴0 2右2轴
  1977. //IsOrder正序false 逆序true
  1978. //EdbInfoType是否是领先指标
  1979. const axisLabelMap: any =
  1980. lang == 'zh'
  1981. ? {
  1982. 0: "右轴",
  1983. 2: "右2轴",
  1984. }
  1985. : {
  1986. 0: "RHS",
  1987. 2: "2-RHS",
  1988. };
  1989. const orderLabelMap: any =
  1990. lang == 'zh'
  1991. ? {
  1992. 1: "逆序",
  1993. }
  1994. : {
  1995. 1: "REV",
  1996. };
  1997. const edbInfoMap: any =
  1998. lang == 'zh'
  1999. ? {
  2000. 0: "领先",
  2001. }
  2002. : {
  2003. 0: "Lead",
  2004. };
  2005. const leadUnitEnMap: any = {
  2006. 年: "Y",
  2007. 季: "Q",
  2008. 月: "M",
  2009. 周: "W",
  2010. 天: "D",
  2011. };
  2012. //英文领先单位转换
  2013. const edbLeadUnit = lang == 'zh' ? LeadUnit : leadUnitEnMap[LeadUnit];
  2014. let axis_tag = axisLabelMap[IsAxis] || "";
  2015. //逆序拼接
  2016. let order_tag = orderLabelMap[Number(IsOrder)]
  2017. ? `${axis_tag ? "," : ""}${orderLabelMap[Number(IsOrder)]}`
  2018. : "";
  2019. //领先拼接
  2020. let edb_tag = edbInfoMap[EdbInfoType]
  2021. ? `${axis_tag || order_tag ? "," : ""}${
  2022. edbInfoMap[EdbInfoType]
  2023. } ${LeadValue}${edbLeadUnit}`
  2024. : "";
  2025. return axis_tag || order_tag || edb_tag
  2026. ? `(${axis_tag}${order_tag}${edb_tag})`
  2027. : "";
  2028. };
  2029. /* 预测配置 分区 */
  2030. const getPredictParams = (
  2031. { LatestDate, MoveLatestDate, PredictChartColor, ChartStyle }: IDataProps,
  2032. chartStyle = ""
  2033. ) => {
  2034. return {
  2035. zoneAxis: "x",
  2036. zones: [
  2037. {
  2038. value: new Date(MoveLatestDate || LatestDate).getTime() + 1,
  2039. },
  2040. {
  2041. dashStyle: "ShortDot",
  2042. color:
  2043. ChartStyle === "column" || chartStyle === "column"
  2044. ? "transparent"
  2045. : PredictChartColor,
  2046. },
  2047. ],
  2048. };
  2049. };
  2050. /* 季节图预测数据 年份=分割点年份做分割 年份>分割点年份全为预测 */
  2051. const getSeasonPredictParams = (timestamp: number) => {
  2052. return timestamp
  2053. ? {
  2054. zoneAxis: "x",
  2055. zones: [
  2056. {
  2057. value: new Date(timestamp).getTime() + 1,
  2058. },
  2059. {
  2060. dashStyle: "ShortDot",
  2061. },
  2062. ],
  2063. }
  2064. : {};
  2065. };
  2066. /* 处理轴的标识线结构 在指定轴位置上拼接标识线
  2067. 0:右轴 1:左轴 2:右2轴 x轴固定3
  2068. axisType表示x轴类型 处理时间轴的值 datetime/null
  2069. */
  2070. const setAxisPlotLines = (axis: number, axisType: any = null) => {
  2071. const { MarkersLines, ChartType } = state.chartInfo;
  2072. if (!MarkersLines) return [];
  2073. let markerLines = JSON.parse(MarkersLines);
  2074. let arr = markerLines.filter((_) => _.isShow && _.axis === axis);
  2075. let plotLines = arr.map((_) => {
  2076. //是否是x时间轴
  2077. let isXDateAxis = axis === 3 && axisType === "datetime";
  2078. let markerValue:number;
  2079. if (isXDateAxis) {
  2080. //季节图x轴额外拼个年份
  2081. let nowYear = ChartType===2 ? new Date(state.dataList[0].DataList[1].DataList
  2082. [0].DataTimestamp).getFullYear() : '';
  2083. markerValue =
  2084. ChartType === 2
  2085. ? new Date(`${nowYear}-${_.value}`).getTime()
  2086. : new Date(_.value).getTime();
  2087. } else {
  2088. markerValue = Number(_.value);
  2089. }
  2090. return {
  2091. value: markerValue,
  2092. dashStyle: _.dashStyle,
  2093. width: Number(_.lineWidth),
  2094. color: _.color,
  2095. label: {
  2096. text: _.text || "",
  2097. verticalAlign: _.textPosition,
  2098. style: {
  2099. color: _.textColor,
  2100. fontSize: _.textFontSize,
  2101. },
  2102. },
  2103. };
  2104. });
  2105. return plotLines;
  2106. };
  2107. /* 处理标识区拼接 axisType表示x轴类型处理时间轴的值 datetime/null */
  2108. const setAxisPlotAreas = (axis: number, axisType: any = null) => {
  2109. const { MarkersAreas, ChartType } = state.chartInfo;
  2110. if (!MarkersAreas) return [];
  2111. let markerAreas = JSON.parse(MarkersAreas);
  2112. let arr = markerAreas.filter((_) => _.isShow && _.axis === axis);
  2113. let plotBands = arr.map((_) => {
  2114. //是否是x时间轴
  2115. let isXDateAxis = axis === 3 && axisType === "datetime";
  2116. let fromMarkerValue:number, toMarkerValue:number;
  2117. if (isXDateAxis) {
  2118. //季节图x轴额外拼个年份
  2119. let nowYear = ChartType===2 ? new Date(state.dataList[0].DataList[1].DataList
  2120. [0].DataTimestamp).getFullYear() : '';
  2121. fromMarkerValue =
  2122. ChartType === 2
  2123. ? new Date(`${nowYear}-${_.fromValue}`).getTime()
  2124. : new Date(_.fromValue).getTime();
  2125. toMarkerValue =
  2126. ChartType === 2
  2127. ? new Date(`${nowYear}-${_.toValue}`).getTime()
  2128. : new Date(_.toValue).getTime();
  2129. } else {
  2130. fromMarkerValue = Number(_.fromValue);
  2131. toMarkerValue = Number(_.toValue);
  2132. }
  2133. //默认label有些偏移 重新归正下
  2134. let positionMapValue = {
  2135. 'top': 12,
  2136. 'middle': 0,
  2137. 'bottom': -10
  2138. }
  2139. return {
  2140. from: fromMarkerValue,
  2141. to: toMarkerValue,
  2142. color: _.color,
  2143. label: {
  2144. text: _.text || "",
  2145. verticalAlign: _.textPosition,
  2146. y: positionMapValue[_.textPosition],
  2147. style: {
  2148. color: _.textColor,
  2149. fontSize: _.textFontSize,
  2150. },
  2151. },
  2152. };
  2153. });
  2154. return plotBands;
  2155. };
  2156. /* ----自定义上下限相关--- */
  2157. const setLimitData = (tableData:any=[],data:{DataResp:any})=>{
  2158. const {
  2159. //左右轴极值字段
  2160. LeftMin=0,LeftMax=0,
  2161. RightMin=0,RightMax=0,
  2162. Right2Min=0,Right2Max=0,
  2163. MinMaxSave
  2164. } = state.chartInfo
  2165. if(MinMaxSave){
  2166. state.chartLimit.min = Number(LeftMin)
  2167. state.chartLimit.max = Number(LeftMax)
  2168. state.chartLimit.rightMin = Number(RightMin)
  2169. state.chartLimit.rightMax = Number(RightMax)
  2170. state.chartLimit.rightTwoMin = Number(Right2Min)
  2171. state.chartLimit.rightTwoMax = Number(Right2Max)
  2172. //若用户修改过,则检测轴的上下限是否为空,若为空,则需要计算对应轴的上下限
  2173. checkLimit(tableData)
  2174. }else{
  2175. calcYAxislimit(tableData,data.DataResp?data.DataResp:{})
  2176. }
  2177. }
  2178. const checkLimit = (tableData:any=[])=>{
  2179. //散点图单独处理
  2180. if(state.chartInfo.ChartType===5){
  2181. if(tableData[1]){
  2182. if(Number(state.chartLimit.min)===0&&Number(state.chartLimit.max)===0){
  2183. state.chartLimit.min = tableData[1].MinData
  2184. state.chartLimit.max = tableData[1].MaxData
  2185. }
  2186. }
  2187. return
  2188. }
  2189. //若轴的上下限均为0,则不管用户有没有修改过,都重新赋值
  2190. if(Number(state.chartLimit.min)===0&&Number(state.chartLimit.max)===0){
  2191. const leftData = tableData.filter((i:IDataProps)=>i.IsAxis===1).map((i:IDataProps)=>[Number(i.MinData),Number(i.MaxData)])
  2192. if(leftData.length){
  2193. const {Max,Min} = calcLimit(leftData.flat())
  2194. state.chartLimit.min = Min
  2195. state.chartLimit.max = Max
  2196. }else{
  2197. state.chartLimit.min = 0
  2198. state.chartLimit.max = 0
  2199. }
  2200. }
  2201. if(Number(state.chartLimit.rightMin)===0&&Number(state.chartLimit.rightMax)===0){
  2202. const rightData = tableData.filter((i:IDataProps) => !i.IsAxis).map((i:IDataProps)=>[Number(i.MinData),Number(i.MaxData)])
  2203. if(rightData.length){
  2204. const {Max,Min} = calcLimit(rightData.flat())
  2205. state.chartLimit.rightMin = Min
  2206. state.chartLimit.rightMax = Max
  2207. }else{
  2208. state.chartLimit.rightMin = 0
  2209. state.chartLimit.rightMax = 0
  2210. }
  2211. }
  2212. if(Number(state.chartLimit.rightTwoMin)===0&&Number(state.chartLimit.rightTwoMax)===0){
  2213. const rightTwoData = tableData.filter((i:IDataProps)=>i.IsAxis===2).map((i:IDataProps)=>[Number(i.MinData),Number(i.MaxData)])
  2214. if(rightTwoData.length){
  2215. const {Max,Min} = calcLimit(rightTwoData.flat())
  2216. state.chartLimit.rightTwoMin = Min
  2217. state.chartLimit.rightTwoMax = Max
  2218. }else{
  2219. state.chartLimit.rightTwoMin = 0
  2220. state.chartLimit.rightTwoMax = 0
  2221. }
  2222. }
  2223. }
  2224. /* 计算y轴上下限 */
  2225. const calcYAxislimit = (tableData:any=[],DataResp:any={})=>{
  2226. //散点图单独处理
  2227. if(state.chartInfo.ChartType===5){
  2228. if(tableData[1]){
  2229. state.chartLimit.min = tableData[1].MinData
  2230. state.chartLimit.max = tableData[1].MaxData
  2231. }
  2232. return
  2233. }
  2234. //分组
  2235. const leftData = tableData.filter((i:IDataProps) => i.IsAxis === 1).map((i:IDataProps) => [Number(i.MinData), Number(i.MaxData)])
  2236. const rightData = tableData.filter((i:IDataProps) => !i.IsAxis).map((i:IDataProps) => [Number(i.MinData), Number(i.MaxData)])
  2237. const rightTwoData = tableData.filter((i:IDataProps) => i.IsAxis === 2).map((i:IDataProps) => [Number(i.MinData), Number(i.MaxData)])
  2238. //计算最大最小值
  2239. if (leftData.length) {
  2240. const {
  2241. Max,
  2242. Min
  2243. } = calcLimit(leftData.flat())
  2244. state.chartLimit.min = Min
  2245. state.chartLimit.max = Max
  2246. } else {
  2247. state.chartLimit.min = 0
  2248. state.chartLimit.max = 0
  2249. }
  2250. if (rightData.length) {
  2251. const {
  2252. Max,
  2253. Min
  2254. } = calcLimit(rightData.flat())
  2255. state.chartLimit.rightMin = Min
  2256. state.chartLimit.rightMax = Max
  2257. } else {
  2258. state.chartLimit.rightMin = 0
  2259. state.chartLimit.rightMax = 0
  2260. }
  2261. if (rightTwoData.length) {
  2262. const {
  2263. Max,
  2264. Min
  2265. } = calcLimit(rightTwoData.flat())
  2266. state.chartLimit.rightTwoMin = Min
  2267. state.chartLimit.rightTwoMax = Max
  2268. } else {
  2269. state.chartLimit.rightTwoMin = 0
  2270. state.chartLimit.rightTwoMax = 0
  2271. }
  2272. //季节性图-右轴单独处理
  2273. if(state.chartInfo.ChartType===2){
  2274. if(DataResp.RightAxis&&DataResp.RightAxis.IsAdd&&DataResp.RightAxis.IsShow){
  2275. if(DataResp.RightAxis.IndicatorType===1){
  2276. state.chartLimit.rightMin = DataResp.RightAxis.EdbInfoList[0].MinData||0
  2277. state.chartLimit.rightMax = DataResp.RightAxis.EdbInfoList[0].MaxData||0
  2278. }else{
  2279. state.chartLimit.rightMin = tableData[1].MinData||0
  2280. state.chartLimit.rightMax = tableData[1].MaxData||0
  2281. }
  2282. }
  2283. }
  2284. }
  2285. const calcLimit = (arr:any)=>{
  2286. return {
  2287. Max: Math.max(...arr),
  2288. Min: Math.min(...arr)
  2289. }
  2290. }
  2291. /*-------------------- */