render.js 89 KB

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