render.js 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843
  1. // 图渲染逻辑模块
  2. import {onMounted,ref,nextTick,reactive} from 'vue'
  3. import {chartDefaultOpts,scatterXAxis,basicYAxis,basicXAxis,leadUnitEnMap,relevanceUnitEnMap,seasonOptions} 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,12].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. Highcharts.setOptions({ global: { useUTC:data.ChartInfo.ChartType==2?true:false } });
  144. //stock不支持线形图只支持时间图 某些用chart
  145. let is_linear = chartOpt.series
  146. ? chartOpt.series.some(_ => _.chartType === 'linear')
  147. : false ;
  148. is_linear ?ChartIns=Highcharts.chart(RenderDomId.value,options.value) : ChartIns=Highcharts.stockChart(RenderDomId.value,options.value);
  149. return ChartIns
  150. }
  151. //主题色一些外层公用配置 目前只有绘图区和legend和colors
  152. function setThemeOptions() {
  153. if(!chartData.value.ChartInfo.ChartThemeStyle) return {}
  154. let chartTheme = JSON.parse(chartData.value.ChartInfo.ChartThemeStyle)
  155. return {
  156. legend: {
  157. ...chartDefaultOpts.legend,
  158. ...chartTheme.legendOptions
  159. },
  160. chart: {
  161. ...chartDefaultOpts.chart,
  162. ...chartTheme.drawOption
  163. },
  164. colors: chartTheme.colorsOptions
  165. }
  166. }
  167. /* 处理轴的标识线结构 在指定轴位置上拼接标识线
  168. 0:右轴 1:左轴 2:右2轴 x轴固定3
  169. axisType表示x轴类型 处理时间轴的值 datetime/null
  170. */
  171. function setAxisPlotLines(axis,axisType) {
  172. const { MarkersLines,ChartType } = chartData.value.ChartInfo;
  173. const { EdbInfoList } = chartData.value;
  174. if(!MarkersLines) return []
  175. let markerLines = JSON.parse(MarkersLines);
  176. let arr = markerLines.filter(_ => _.isShow&&_.axis===axis)
  177. let plotLines = arr.map(_ => {
  178. //是否是x时间轴
  179. let isXDateAxis = axis===3&&axisType==='datetime';
  180. let markerValue;
  181. if(isXDateAxis) {
  182. //季节图x轴额外拼个年份
  183. let nowYear = ChartType===2 ? new Date(EdbInfoList[0].DataList[1].DataList
  184. [0].DataTimestamp).getFullYear() : '';
  185. markerValue = ChartType===2
  186. ? new Date(`${nowYear}-${_.value}`).getTime()
  187. : new Date(_.value).getTime()
  188. }else {
  189. markerValue = Number(_.value)
  190. }
  191. return {
  192. value: markerValue,
  193. dashStyle: _.dashStyle,
  194. width: Number(_.lineWidth),
  195. color: _.color,
  196. label: {
  197. text: _.text||'',
  198. verticalAlign: _.textPosition,
  199. style: {
  200. color: _.textColor,
  201. fontSize: _.textFontSize
  202. }
  203. }
  204. }
  205. })
  206. return plotLines
  207. }
  208. /* 处理标识区拼接 axisType表示x轴类型处理时间轴的值 datetime/null */
  209. function setAxisPlotAreas(axis,axisType) {
  210. const { MarkersAreas,ChartType } = chartData.value.ChartInfo;
  211. const { EdbInfoList } = chartData.value;
  212. if(!MarkersAreas) return []
  213. let markerAreas = JSON.parse(MarkersAreas);
  214. let arr = markerAreas.filter(_ => _.isShow&&_.axis===axis)
  215. let plotBands = arr.map(_ => {
  216. //是否是x时间轴
  217. let isXDateAxis = axis===3&&axisType==='datetime';
  218. let fromMarkerValue,toMarkerValue;
  219. if(isXDateAxis) {
  220. //季节图x轴额外拼个年份
  221. let nowYear = ChartType===2 ? new Date(EdbInfoList[0].DataList[1].DataList
  222. [0].DataTimestamp).getFullYear() : '';
  223. fromMarkerValue = ChartType===2
  224. ? new Date(`${nowYear}-${_.fromValue}`).getTime()
  225. : new Date(_.fromValue).getTime()
  226. toMarkerValue = ChartType===2
  227. ? new Date(`${nowYear}-${_.toValue}`).getTime()
  228. : new Date(_.toValue).getTime()
  229. }else {
  230. fromMarkerValue = Number(_.fromValue);
  231. toMarkerValue = Number(_.toValue);
  232. }
  233. //默认label有些偏移 重新归正下
  234. let positionMapValue = {
  235. 'top': 12,
  236. 'middle': 0,
  237. 'bottom': -10
  238. }
  239. return {
  240. from: fromMarkerValue,
  241. to: toMarkerValue,
  242. color: _.color,
  243. label: {
  244. text: _.text||'',
  245. verticalAlign: _.textPosition,
  246. y: positionMapValue[_.textPosition],
  247. style: {
  248. color: _.textColor,
  249. fontSize: _.textFontSize
  250. }
  251. }
  252. }
  253. })
  254. return plotBands
  255. }
  256. /* 预测配置 分区 */
  257. function getPredictParams ({LatestDate,PredictChartColor}) {
  258. return {
  259. zoneAxis: 'x',
  260. zones: [{
  261. value: new Date(LatestDate).getTime()+1
  262. }, {
  263. dashStyle: 'ShortDot',
  264. color: PredictChartColor
  265. }]
  266. }
  267. }
  268. /* 季节图预测数据 年份=分割点年份做分割 年份>分割点年份全为预测 */
  269. function getSeasonPredictParams (timestamp){
  270. return timestamp
  271. ? {
  272. zoneAxis: 'x',
  273. zones: [{
  274. value: new Date(timestamp).getTime()+1
  275. }, {
  276. dashStyle: 'ShortDot',
  277. }]
  278. }
  279. : {}
  280. }
  281. // 查询范围为1年内 x轴显示为月/日 否则默认年/月
  282. function xTimeDiffer(minTime,maxTime,dateType){
  283. //年限差
  284. let year_differ=moment(maxTime).diff(moment(minTime),'years',true)
  285. // console.log('年限差',year_differ)
  286. if ([5, 6].includes(dateType) && year_differ <= 1) {
  287. return true
  288. } else {
  289. return false
  290. }
  291. }
  292. /* 拼接动态的指标名称小标签 */
  293. function concatDynamicTag(item,lang){
  294. const { IsAxis,IsOrder,EdbInfoType,LeadValue,LeadUnit } = item;
  295. // IsAxis左轴1 右轴0 2右2轴
  296. //IsOrder正序false 逆序true
  297. //IsOrder正序false 逆序true
  298. //IsOrder正序false 逆序true
  299. //EdbInfoType是否是领先指标
  300. const axisLabelMap =lang=='zh'? {
  301. 0: '右轴',
  302. 2: '右2轴'
  303. }:{
  304. 0: 'RHS',
  305. 2: '2-RHS'
  306. }
  307. const orderLabelMap =lang=='zh'? {
  308. 1: '逆序'
  309. }:{
  310. 1: 'REV'
  311. }
  312. const edbInfoMap =lang=='zh'? {
  313. 0: '领先'
  314. }:{
  315. 0: 'Lead'
  316. }
  317. //英文领先单位转换
  318. const leadUnit = lang==='zh' ? LeadUnit : leadUnitEnMap[LeadUnit];
  319. let axis_tag = axisLabelMap[IsAxis] || '';
  320. //逆序拼接
  321. let order_tag = orderLabelMap[Number(IsOrder)] ? `${axis_tag ? ',': ''}${orderLabelMap[Number(IsOrder)]}` : ''
  322. //领先拼接
  323. let edb_tag = edbInfoMap[EdbInfoType] ? `${(axis_tag||order_tag) ? ',' : '' }${edbInfoMap[EdbInfoType]}${LeadValue}${leadUnit}` : '';
  324. let dynamic_tag = (axis_tag || order_tag || edb_tag) ? `(${axis_tag}${order_tag}${edb_tag})` : '';
  325. return dynamic_tag
  326. }
  327. /* 拼接数据列动态name */
  328. function setDyncmicSerieName (item,dynamic_arr,lang='zh') {
  329. let temName =''
  330. /* if(lang=='zh'){
  331. temName= dynamic_arr.length > 1
  332. ? `${item.EdbName}(${item.SourceName})${concatDynamicTag(item,'zh')}`
  333. : `${item.EdbName}${concatDynamicTag(item,'zh')}`
  334. }else{
  335. temName=item.EdbNameEn?`${item.EdbNameEn}${concatDynamicTag(item,'en')}`:''
  336. } */
  337. const temNameEn = item.EdbNameEn?`${item.EdbNameEn}${concatDynamicTag(item,'en')}`:''
  338. const temNameZh = dynamic_arr.length > 1
  339. ? `${item.EdbAliasName||item.EdbName}(${item.SourceName})${concatDynamicTag(item,'zh')}`
  340. : `${item.EdbAliasName||item.EdbName}${concatDynamicTag(item,'zh')}`
  341. temName = lang=='zh'?temNameZh:temNameEn?temNameEn:temNameZh
  342. if(temName.length>20){
  343. let temArr=[]
  344. for(let i=0;i<temName.length/20;i++){
  345. temArr.push(temName.slice(i*20,i*20+20))
  346. }
  347. temName=temArr.join('<br>')
  348. }
  349. return temName
  350. }
  351. /* 指标顺序调整 IsAxis: 0右轴 1左轴 2右2*/
  352. function changeEdbOrder (data){
  353. // 左轴指标
  354. let left_edbs = data.filter(_ => _.IsAxis===1);
  355. //右轴指标
  356. let right_edbs = data.filter(_ => !_.IsAxis);
  357. // 右2轴指标
  358. let right_two_edbs = data.filter(_ => _.IsAxis === 2);
  359. // 按 左 右 右2顺序排列
  360. return [left_edbs,right_edbs,right_two_edbs].flat(Infinity);
  361. }
  362. //检查图表英文配置是否完整
  363. function checkChartEnData(){
  364. let result = true
  365. //图表名称:this.chartInfo.ChartNameEn
  366. if(!chartData.value.ChartInfo.ChartNameEn){
  367. result = false
  368. }
  369. //指标名称:this.dataList[].EdbNameEn
  370. //指标单位:this.dataList[].UnitEn
  371. chartData.value.EdbInfoList.forEach(item=>{
  372. if(!item.EdbNameEn){
  373. result = false
  374. }
  375. if(chartData.value.ChartInfo.ChartType!==10&&item.Unit&&!item.UnitEn){
  376. result = false
  377. }
  378. })
  379. return result
  380. }
  381. // 设置图表显示的语言
  382. function setChartLang(changeLangIsCheck){
  383. if(changeLangIsCheck&&!checkChartEnData()) return
  384. const {ChartType,Source} = chartData.value.ChartInfo
  385. if(Source==1){
  386. // 散点图
  387. if(ChartType == 5){
  388. options.value.yAxis.title.text = LangType.value == 'zh' ? options.value.yAxis.title.textZh : options.value.yAxis.title.textEn;
  389. // options.value.yAxis.title.style = LangType.value == 'zh' ? {} : options.value.yAxis.title.styleEn;
  390. options.value.xAxis.title.text = LangType.value == 'zh' ? options.value.xAxis.title.textZh : options.value.xAxis.title.textEn
  391. // options.value.xAxis.title.style = LangType.value == 'zh' ? {} : options.value.xAxis.title.styleEn;
  392. options.value.series.forEach(item => {
  393. item.name = LangType.value == 'zh' ? item.nameZh : item.nameEn;
  394. });
  395. options.value.tooltip.formatter = LangType.value == 'zh' ? options.value.tooltip.formatterZh : options.value.tooltip.formatterEn;
  396. }else{
  397. // 单位
  398. options.value.yAxis.forEach(item => {
  399. item.title.text = LangType.value == 'zh' ? item.title.textZh : item.title.textEn;
  400. // item.title.style = LangType.value == 'zh' ? {} : (item.title.styleEn || {})
  401. });
  402. // 图例 名称
  403. if(ChartType != 2){
  404. // 季节图 不更改图例名称
  405. options.value.series.forEach(item => {
  406. item.name = LangType.value == 'zh'
  407. ? item.nameZh
  408. : (item.nameEn!='无英文名称'?item.nameEn:`<span style="color:#999">${item.nameEn}</span>`)
  409. });
  410. }
  411. //截面散点 x轴标题
  412. if(ChartType === 10){
  413. options.value.xAxis.title.text = LangType.value == 'zh' ? options.value.xAxis.title.textZh : options.value.xAxis.title.textEn;
  414. // options.value.xAxis.title.style = LangType.value == 'zh' ? {} : options.value.xAxis.title.styleEn;
  415. options.value.tooltip.formatter = LangType.value == 'zh' ? options.value.tooltip.formatterCh : options.value.tooltip.formatterEn;
  416. options.value.series.forEach(item => {
  417. if(!item.linkedTo) {
  418. item.data.forEach(point => {
  419. point.dataLabels.format = LangType.value == 'zh' ? point.dataLabels.formatZh : (point.dataLabels.formatEn||'无英文标签');
  420. point.dataLabels.color = (LangType.value==='en' && !point.dataLabels.formatEn) ? '#999' : '#333'
  421. })
  422. }
  423. });
  424. }
  425. //柱形图额外设置x轴中英文
  426. if([7,11].includes(ChartType)){
  427. //x轴
  428. options.value.xAxis.categories = chartData.value.XEdbIdValue.map(_ => LangType.value == 'zh'
  429. ? chartData.value.EdbInfoList.find(edb => edb.EdbInfoId===_).EdbAliasName || chartData.value.EdbInfoList.find(edb => edb.EdbInfoId===_).EdbName
  430. : chartData.value.EdbInfoList.find(edb => edb.EdbInfoId===_).EdbNameEn)
  431. }
  432. }
  433. }
  434. if([2,3,4].includes(Source)){
  435. options.value.yAxis.forEach(item => {
  436. item.title.text = LangType.value == 'zh' ? item.title.textZh: item.title.textEn||item.title.textZh
  437. });
  438. //图例
  439. options.value.series.forEach(item => {
  440. item.name = LangType.value == 'en' ?(item.nameEn||item.nameZh) : item.nameZh
  441. });
  442. //tooltip
  443. options.value.tooltip.formatter = LangType.value == 'en'?options.value.tooltip.formatterEn:options.value.tooltip.formatterZh
  444. //x轴
  445. if(Source==2){
  446. options.value.xAxis.categories = commodityXData.value.filter(_=>_.IsHide===0).map(_ => LangType.value == 'en'?_.NameEn:_.Name);
  447. }
  448. if([3].includes(Source)){
  449. options.value.xAxis.title.text=LangType.value == 'en'?(options.value.xAxis.title.textEn||options.value.xAxis.title.textZh):options.value.xAxis.title.textZh
  450. }
  451. }
  452. }
  453. // 设置图标题
  454. function setChartTitle(showChartTitle){
  455. if(showChartTitle){
  456. const ChartInfo=chartData.value.ChartInfo
  457. options.value.title.textZh=ChartInfo.ChartName
  458. options.value.title.textEn=ChartInfo.ChartNameEn
  459. options.value.title.text=LangType.value == 'zh' ?options.value.title.textZh:options.value.title.textEn||options.value.title.textZh
  460. }else{
  461. options.value.title.text=''
  462. }
  463. }
  464. // 截面组合图
  465. function setSectionalCombinationChart(e){
  466. /* 主题样式*/
  467. const chartTheme = e.ChartInfo.ChartThemeStyle ? JSON.parse(e.ChartInfo.ChartThemeStyle) : null;
  468. const {XDataList,UnitList,SeriesList,IsHeap}=e.DataResp;
  469. axisLimitState.leftIndex=SeriesList.findIndex((item) => item.IsAxis===1);
  470. axisLimitState.rightIndex=SeriesList.findIndex((item) => !item.IsAxis);
  471. axisLimitState.rightTwoIndex=SeriesList.findIndex((item) => item.IsAxis ===2);
  472. if(axisLimitState.leftIndex!=-1) {
  473. axisLimitState.hasLeftAxis=true
  474. }
  475. if(axisLimitState.rightIndex!=-1){
  476. axisLimitState.hasRightAxis=true
  477. }
  478. if(axisLimitState.rightTwoIndex!=-1){
  479. axisLimitState.hasRightTwoAxis=true
  480. }
  481. //x轴
  482. const xAxis={
  483. categories:XDataList.map(_=>this.currentLang=='en'?_.NameEn:_.Name),
  484. tickWidth: 1,
  485. labels: {
  486. style:{
  487. ...chartTheme&&chartTheme.xAxisOptions.style
  488. },
  489. },
  490. plotBands: setAxisPlotAreas(3),
  491. plotLines: setAxisPlotLines(3)
  492. }
  493. let yAxis=[]
  494. let seriesData=[]
  495. //有右二轴时排个序 按照左 右 右2的顺序
  496. const chartData = SeriesList.some(_ =>_.IsAxis===2) ? changeEdbOrder(SeriesList) : _.cloneDeep(SeriesList);
  497. chartData.forEach((item,index)=>{
  498. //轴位置值相同的下标
  499. const sameSideIndex = chartData.findIndex(
  500. (i) => i.IsAxis === item.IsAxis
  501. );
  502. const yTitleMap={
  503. 1:['LeftName','LeftNameEn'],
  504. 0:['RightName','RightNameEn'],
  505. 2:['RightTwoName','RightTwoNameEn'],
  506. }
  507. let minLimit = 0,maxLimit = 0
  508. const limitMap = {
  509. 0:['rightMin','rightMax'],
  510. 1:['leftMin','leftMax'],
  511. 2:['rightTwoMin','rightTwoMax']
  512. }
  513. if(limitMap[item.IsAxis]){
  514. minLimit = axisLimitState[`${limitMap[item.IsAxis][0]}`]||0
  515. maxLimit = axisLimitState[`${limitMap[item.IsAxis][1]}`]||0
  516. }
  517. let yItem = {
  518. ...basicYAxis,
  519. title: {
  520. text: UnitList[yTitleMap[item.IsAxis][0]],
  521. textCh:UnitList[yTitleMap[item.IsAxis][0]], // 中文
  522. // 中文不存在,无论英文有无都显示空
  523. textEn:UnitList[yTitleMap[item.IsAxis][0]]?UnitList[yTitleMap[item.IsAxis][1]]:'', // 英文
  524. style:{
  525. ...chartTheme&&chartTheme.yAxisOptions.style
  526. },
  527. align: 'high',
  528. rotation: 0,
  529. y: -12,
  530. // x: (item.IsAxis===0 && this.rightTwoIndex>-1) ? -chartData[this.rightTwoIndex].Unit.length*12 : 0,
  531. textAlign: item.IsAxis===1 ? 'left' : 'right',
  532. reserveSpace: false
  533. },
  534. labels: {
  535. formatter: function (ctx) {
  536. return ctx.value;
  537. },
  538. align: 'center',
  539. x: [0,2].includes(item.IsAxis) ? 5 : -5,
  540. style: {
  541. ...chartTheme&&chartTheme.yAxisOptions.style,
  542. }
  543. },
  544. opposite: [0,2].includes(item.IsAxis),
  545. min: Number(minLimit),
  546. max: Number(maxLimit),
  547. tickWidth: 1,
  548. visible: sameSideIndex === index,
  549. plotBands: setAxisPlotAreas(item.IsAxis),
  550. plotLines: setAxisPlotLines(item.IsAxis)
  551. };
  552. //堆叠图的yAxis必须一致 数据列所对应的y轴
  553. let serie_yIndex = index;
  554. if(IsHeap==1) {
  555. // 类型为堆叠图时公用第一个指标y轴
  556. serie_yIndex = 0;
  557. }
  558. //数据列
  559. let dataArr=item.DataList||[]
  560. // 根据NoDataEdbIndex 将对应位置的值置为null
  561. dataArr.forEach((i,index)=>{
  562. if(item.NoDataEdbIndex.includes(index)){
  563. dataArr[index]=null
  564. }
  565. })
  566. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  567. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  568. let obj={
  569. data:dataArr,
  570. type: item.ChartStyle||'',
  571. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  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 =e.ChartInfo.Source===12?item.ConvertUnit : item.ConvertUnit||item.Unit
  813. const textEn =e.ChartInfo.Source===12?item.ConvertEnUnit : 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. const {RightAxis:SeasonRightConfig={}} = e.DataResp||{}
  916. axisLimitState.rightIndex=SeasonRightConfig.IsShow?1:-1
  917. axisLimitState.rightTwoIndex=-1
  918. /* 主题样式*/
  919. const chartTheme = e.ChartInfo.ChartThemeStyle ? JSON.parse(e.ChartInfo.ChartThemeStyle) : null;
  920. let chartData={}
  921. const data=e.EdbInfoList[0]
  922. const calendarType=e.ChartInfo.Calendar||'公历'
  923. const colorsArr=chartTheme&&chartTheme.colorsOptions.reverse();
  924. let series=[],yAxis=[]
  925. //农历默认选中一年数据并隐藏按钮 公历显示全部数据
  926. // 农历数据需要去除第一项 农历和公历处理逻辑一样
  927. const chartDataHandle=calendarType === '农历'?
  928. data.DataList.filter((item, index) => index > 0):
  929. data.DataList
  930. // 跟颜色对应
  931. chartTheme && (chartTheme.lineOptionList=chartTheme.lineOptionList.reverse().slice(-chartDataHandle.length))
  932. let maxDateRange=0
  933. // if(calendarType==='公历'){
  934. //常规左轴
  935. chartDataHandle.forEach((item,index)=>{
  936. //预测指标配置
  937. let predict_params = data.EdbInfoCategoryType === 1 ? getSeasonPredictParams(item.CuttingDataTimestamp) : {};
  938. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  939. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  940. let seriesItem={
  941. data:[],
  942. dataGrouping:{
  943. enabled:false
  944. },
  945. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || data.ChartStyle,
  946. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  947. yAxis:0,
  948. name:item.ChartLegend,
  949. lineWidth: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 1,
  950. // color:colorsArr.slice(-chartDataHandle.length)[lineIndex], //与PC端的配置不同步,导致两边 十条之后的线条颜色不对应
  951. visible:true,
  952. marker:chartTheme && chartTheme.lineOptionList[lineIndex].dataMark && chartTheme.lineOptionList[lineIndex].dataMark!='none'?{
  953. enabled:true,
  954. symbol: chartTheme.lineOptionList[lineIndex].markType || 'circle',
  955. fillColor:chartTheme.lineOptionList[lineIndex].markColor,
  956. radius: chartTheme.lineOptionList[lineIndex].markSize
  957. }:{},
  958. ...predict_params
  959. }
  960. item.DataList=item.DataList||[]
  961. const data_array=item.DataList||[]
  962. if(data_array.length>0){
  963. let dateRange = item.DataList[item.DataList.length-1].DataTimestamp - item.DataList[0].DataTimestamp
  964. // 时间范围
  965. maxDateRange=Math.max(maxDateRange,dateRange)
  966. }
  967. for(let i of item.DataList){
  968. seriesItem.data.push([i.DataTimestamp, i.Value])
  969. }
  970. series.push(seriesItem)
  971. })
  972. chartData.colors = colorsArr.slice(-chartDataHandle.length)
  973. //同期上下限/均线/标准差
  974. const {MaxMinLimits={},SamePeriodAverage={},SamePeriodStandardDeviation={}} = e.DataResp||{}
  975. if(MaxMinLimits.IsShow&&MaxMinLimits.List&&MaxMinLimits.List.length){
  976. let serieItem = {
  977. type:'arearange',//上下限是一个范围
  978. data:[],
  979. name:MaxMinLimits.Legend||'同期上下限',
  980. color:MaxMinLimits.Color||'#075EEE' ,
  981. fillOpacity:parseRgbaColor(MaxMinLimits.Color||'')>0.75?0.75:parseRgbaColor(MaxMinLimits.Color||'') //透明度最高0.75
  982. }
  983. MaxMinLimits.List.forEach(item=>{
  984. serieItem.data.push([item.DataTimestamp,item.MinValue,item.MaxValue])
  985. })
  986. series.push(serieItem)
  987. }
  988. if(SamePeriodAverage.IsShow&&SamePeriodAverage.List){
  989. let serieItem = {
  990. type:'line',
  991. data:[],
  992. lineWidth:SamePeriodAverage.LineWidth,
  993. dashStyle:SamePeriodAverage.LineType,
  994. name:SamePeriodAverage.Legend||'同期均值',
  995. color:SamePeriodAverage.Color||'#075EEE'
  996. }
  997. SamePeriodAverage.List.forEach(item=>{
  998. serieItem.data.push([item.DataTimestamp,item.Value])
  999. })
  1000. series.push(serieItem)
  1001. }
  1002. if(SamePeriodStandardDeviation.IsShow&&SamePeriodStandardDeviation.List){
  1003. let serieItem = {
  1004. type:'arearange',//标准差也是一个范围
  1005. data:[],
  1006. name:SamePeriodStandardDeviation.Legend||'同期标准差',
  1007. color:SamePeriodStandardDeviation.Color||'#075EEE',
  1008. fillOpacity:parseRgbaColor(SamePeriodStandardDeviation.Color||'')>0.75?0.75:parseRgbaColor(SamePeriodStandardDeviation.Color||'')
  1009. }
  1010. SamePeriodStandardDeviation.List.forEach(item=>{
  1011. serieItem.data.push([item.DataTimestamp,item.MinValue,item.MaxValue])
  1012. })
  1013. series.push(serieItem)
  1014. }
  1015. //右轴
  1016. if(SeasonRightConfig.IsShow){
  1017. //右轴的设置
  1018. let serieConfig = SeasonRightConfig.Style==='column'?{
  1019. //柱形
  1020. type:'column',
  1021. color:SeasonRightConfig.ChartColor
  1022. }:{
  1023. //标记点
  1024. type:'spline',
  1025. lineWidth:SeasonRightConfig.LineWidth,
  1026. dashStyle:SeasonRightConfig.LineStyle,
  1027. color:SeasonRightConfig.IsConnected?SeasonRightConfig.LineColor:'rgba(255, 255, 255, 0)',//没有连线颜色设置为透明
  1028. marker:{
  1029. enabled:true,
  1030. symbol:SeasonRightConfig.Shape,
  1031. fillColor:SeasonRightConfig.ChartColor,
  1032. radius:SeasonRightConfig.Size
  1033. },
  1034. }
  1035. let serieItem = {
  1036. ...serieConfig,
  1037. name:SeasonRightConfig.Legend||'',
  1038. data:[],
  1039. yAxis:1,
  1040. }
  1041. const DataList = (SeasonRightConfig.IndicatorType===1?SeasonRightConfig.EdbInfoList[0].DataList:e.EdbInfoList[1]?.DataList)||[]
  1042. DataList.forEach(item=>{
  1043. serieItem.data.push([item.DataTimestamp,item.Value])
  1044. })
  1045. series.push(serieItem)
  1046. }
  1047. //获取上下限
  1048. let minLimit = 0,maxLimit = 0,rightMin = 0,rightMax = 0
  1049. //非ETA图库不使用自定义上下限 非ETA图库的季节性图也不能设置右轴
  1050. if(!useSelfLimit){
  1051. minLimit = data.MinData
  1052. maxLimit = data.MaxData
  1053. }else{
  1054. minLimit = axisLimitState.leftMin||0
  1055. maxLimit = axisLimitState.leftMax||0
  1056. //右轴上下限设置
  1057. if(axisLimitState.rightIndex!==-1){
  1058. rightMin = axisLimitState.rightMin||0
  1059. rightMax = axisLimitState.rightMax||0
  1060. }
  1061. }
  1062. const textZh = data.ConvertUnit||data.Unit
  1063. const textEn = data.ConvertEnUnit||data.UnitEn||data.ConvertUnit||data.Unit
  1064. yAxis=[{
  1065. IsAxis:data.IsAxis,
  1066. labels: {
  1067. align: 'center',
  1068. y:5,
  1069. style: {
  1070. ...chartTheme&&chartTheme.yAxisOptions.style
  1071. }
  1072. },
  1073. title: {
  1074. text: `${textZh}`,
  1075. textZh:textZh, // 中文
  1076. // 中文不存在,无论英文有无都显示空
  1077. textEn:textZh?textEn||'英文单位':'', // 英文
  1078. align: 'high',
  1079. rotation: 0,
  1080. y: -5,
  1081. x: 0,
  1082. textAlign: 'left',
  1083. reserveSpace: false,
  1084. style:{
  1085. ...chartTheme&&chartTheme.yAxisOptions.style
  1086. },
  1087. },
  1088. max: Number(maxLimit),
  1089. min: Number(minLimit),
  1090. plotBands: setAxisPlotAreas(1),
  1091. plotLines: setAxisPlotLines(1),
  1092. lineWidth: 1,
  1093. lineColor: '#bfbfbf',
  1094. tickColor: '#bfbfbf',
  1095. offset: 0,
  1096. opposite: false,
  1097. reversed: false,
  1098. visible: true,
  1099. gridLineWidth: 0,
  1100. tickWidth: 1,
  1101. tickLength:5,
  1102. tickPosition: 'inside',
  1103. endOnTick: false,
  1104. startOnTick: false,
  1105. showLastLabel: true, //显示最后刻度值
  1106. tickPixelInterval: 50,
  1107. // chartEdbInfo:item//指标数据
  1108. }]
  1109. //如果有右轴,yAxis加上右轴
  1110. if(SeasonRightConfig.IsShow){
  1111. const rightEdb = (SeasonRightConfig.IndicatorType===1?SeasonRightConfig.EdbInfoList[0]:e.EdbInfoList[1])||{Unit:''}
  1112. //左轴同比:text为空或% 右轴指标:取指标单位
  1113. if(SeasonRightConfig.IndicatorType===1){
  1114. rightEdb.Unit = SeasonRightConfig.NumFormat===1?'%':''
  1115. }else{
  1116. rightEdb.Unit = e.EdbInfoList[1]&&(e.EdbInfoList[1].ConvertUnit||e.EdbInfoList[1].Unit)||''
  1117. }
  1118. yAxis.push({
  1119. ...seasonOptions.yAxis,
  1120. opposite: true,//右轴
  1121. labels: {
  1122. align: 'center',
  1123. y:5,
  1124. style: {
  1125. ...chartTheme&&chartTheme.yAxisOptions.style
  1126. }
  1127. },
  1128. title: {
  1129. text: rightEdb.Unit||'',
  1130. style:{
  1131. ...chartTheme&&chartTheme.yAxisOptions.style
  1132. },
  1133. align: 'high',
  1134. rotation: 0,
  1135. y: -5,
  1136. x: 0,
  1137. textAlign: 'right',
  1138. reserveSpace: false,
  1139. },
  1140. max: Number(rightMax),
  1141. min: Number(rightMin),
  1142. })
  1143. }
  1144. chartData.series=series
  1145. chartData.yAxis=yAxis
  1146. // chartData.rangeSelector=rangeSelector
  1147. // 设置坐标轴极值
  1148. axisLimitState.hasLeftAxis=true
  1149. if(!useSelfLimit){
  1150. axisLimitState.leftMin=Number(data.MinData)
  1151. axisLimitState.leftMax=Number(data.MaxData)
  1152. }
  1153. // 季节图x轴显示月/日
  1154. let xAxis={
  1155. tickPosition: 'inside',
  1156. lineColor: '#bfbfbf',
  1157. tickColor: '#bfbfbf',
  1158. tickLength:5,
  1159. type: 'datetime',
  1160. ordinal: false,
  1161. dateTimeLabelFormats: {
  1162. day: '%y/%m',
  1163. week: '%y/%m',
  1164. month: '%y/%m',
  1165. year: '%y/%m',
  1166. },
  1167. labels: {
  1168. formatter: (ctx)=> {
  1169. return HighchartsFormat.dateFormat('%m/%d', ctx.value)
  1170. },
  1171. style: {
  1172. ...chartTheme&&chartTheme.xAxisOptions.style
  1173. }
  1174. },
  1175. tickInterval:screen.value === 'phone'?maxDateRange/6:undefined,//季节图
  1176. plotBands: setAxisPlotAreas(3,'datetime'),
  1177. plotLines: setAxisPlotLines(3,'datetime')
  1178. }
  1179. chartData.xAxis=[xAxis]
  1180. // 季节图提示框显示 月/日
  1181. chartData.tooltip={
  1182. split: false,
  1183. shared: true,
  1184. dateTimeLabelFormats: {
  1185. // 时间格式化字符
  1186. day: '%m/%d',
  1187. week: '%m/%d',
  1188. month: '%m/%d',
  1189. year: '%m/%d',
  1190. },
  1191. xDateFormat: '%m/%d',
  1192. }
  1193. return {
  1194. ...chartData,
  1195. // title: {
  1196. // enabled: true,
  1197. // text:e.ChartInfo.ChartName
  1198. // },
  1199. // legend:{
  1200. // enabled:true,
  1201. // verticalAlign: 'top',
  1202. // y:-10,
  1203. // x:(10 * data.Unit.length)/2
  1204. // }
  1205. }
  1206. }
  1207. //堆叠图/组合图设置
  1208. //本来和曲线图逻辑基本一致兼容下即可 为了以后便于维护和阅读还是拆开写吧
  1209. function setStackOrCombinChart(e){
  1210. const data=e.EdbInfoList
  1211. //图表类型
  1212. const chartTypeMap = {
  1213. 3: 'areaspline',
  1214. 4: 'column',
  1215. 6: ''
  1216. };
  1217. let chartStyle = chartTypeMap[e.ChartInfo.ChartType];
  1218. /* 主题样式*/
  1219. const chartTheme = e.ChartInfo.ChartThemeStyle ? JSON.parse(e.ChartInfo.ChartThemeStyle) : null;
  1220. let series=[]
  1221. let yAxis=[]
  1222. let xAxis = {}
  1223. let ExtraConfig={}
  1224. let temYLeftArr=[]
  1225. let temYRightArr=[]
  1226. let temYRightTwoArr = []
  1227. let temYLeftIndex,temYRightIndex,temYRightTwoIndex;
  1228. let minAndMaxTimeTemArr=[]//存放所有指标的最大最小时间
  1229. //有右二轴时排个序 按照左 右 右2的顺序
  1230. let newData = data.some(_ =>_.IsAxis===2) ? changeEdbOrder(data) : data;
  1231. if(e.ChartInfo.ChartType===3 && e.ChartInfo.ExtraConfig){
  1232. ExtraConfig=JSON.parse(e.ChartInfo.ExtraConfig)
  1233. }
  1234. newData.forEach((item,index)=>{
  1235. //轴位置值相同的下标
  1236. let sameSideIndex = newData.findIndex(i => i.IsAxis === item.IsAxis);
  1237. //堆叠图的yAxis必须一致 数据列所对应的y轴
  1238. let serie_yIndex = index;
  1239. if([4].includes(e.ChartInfo.ChartType) || (e.ChartInfo.ChartType ===3 && ExtraConfig.IsHeap==1)) {
  1240. // 类型为堆叠图时公用第一个指标y轴
  1241. serie_yIndex = 0;
  1242. } else if(e.ChartInfo.ChartType ===6 && ['areaspline','column'].includes(item.ChartStyle)) {
  1243. // 组合图找第一个堆叠柱状或面积的作为公用
  1244. serie_yIndex = newData.findIndex(i => i.ChartStyle === item.ChartStyle);
  1245. }
  1246. //数据对应的y轴是公用轴则配置也共享
  1247. item.IsAxis = serie_yIndex === index ? item.IsAxis : newData[serie_yIndex].IsAxis;
  1248. item.IsOrder = serie_yIndex === index ? item.IsOrder : newData[serie_yIndex].IsOrder;
  1249. temYLeftIndex = [4].includes(e.ChartInfo.ChartType)
  1250. ? (newData[serie_yIndex].IsAxis ? serie_yIndex : -1)
  1251. : data.findIndex((item) => item.IsAxis===1);
  1252. temYRightIndex = [4].includes(e.ChartInfo.ChartType)
  1253. ? (newData[serie_yIndex].IsAxis ? -1 : serie_yIndex)
  1254. : data.findIndex((item) => !item.IsAxis);
  1255. temYRightTwoIndex = [4].includes(e.ChartInfo.ChartType)
  1256. ? -1
  1257. : data.findIndex((item) => item.IsAxis===2);
  1258. axisLimitState.leftIndex=temYLeftIndex
  1259. axisLimitState.rightIndex=temYRightIndex
  1260. axisLimitState.rightTwoIndex=temYRightTwoIndex
  1261. let dynamic_title = item.EdbName;
  1262. let dynamic_arr = newData.filter(
  1263. (item) => dynamic_title === item.EdbName
  1264. );
  1265. //处理数据列name
  1266. let temName= setDyncmicSerieName(item,dynamic_arr,'zh')
  1267. let temNameEN=setDyncmicSerieName(item,dynamic_arr,'en')
  1268. //预测指标配置
  1269. let predict_params = item.EdbInfoCategoryType === 1 ? getPredictParams(item) : {};
  1270. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  1271. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index;
  1272. //堆叠控制
  1273. let stacking = undefined;
  1274. if(e.ChartInfo.ChartType===4) {
  1275. stacking = 'normal';
  1276. }else if(e.ChartInfo.ChartType===6) {
  1277. stacking = !e.DataResp.IsHeap ? undefined:'normal';
  1278. }else if(e.ChartInfo.ChartType===3&&ExtraConfig.IsHeap) {
  1279. stacking = ExtraConfig.HeapWay===1?'normal':'percent';
  1280. }
  1281. let seriesItemObj={
  1282. data:[],
  1283. dataGrouping:{
  1284. enabled:false
  1285. },
  1286. type: e.ChartInfo.ChartType !== 3?(chartStyle || item.ChartStyle):ExtraConfig.IsHeap==1?'area':((chartTheme && chartTheme.lineOptionList[lineIndex].lineType) || item.ChartStyle),
  1287. yAxis:serie_yIndex,
  1288. name:temName,
  1289. nameZh:temName,
  1290. nameEn:temNameEN,
  1291. color: item.ChartColor,
  1292. lineWidth: Number(item.ChartWidth)||(chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 1,
  1293. fillColor: (e.ChartInfo.ChartType === 3 || (e.ChartInfo.ChartType === 6 && item.ChartStyle === 'areaspline')) ? item.ChartColor : undefined,
  1294. visible:true,
  1295. LatestDate:item.LatestDate,
  1296. LatestValue:item.LatestValue,
  1297. ...predict_params,
  1298. stacking,
  1299. threshold: (e.ChartInfo.ChartType==3&&item.ChartScale)
  1300. ? Number(item.ChartScale)
  1301. : 0
  1302. }
  1303. item.DataList = item.DataList || [];
  1304. for (let i of item.DataList) {
  1305. seriesItemObj.data.push([i.DataTimestamp, i.Value]);
  1306. }
  1307. series.push(seriesItemObj)
  1308. //获取上下限
  1309. let minLimit = 0,maxLimit = 0
  1310. //非ETA图库不使用自定义上下限
  1311. if(!useSelfLimit){
  1312. minLimit = newData[sameSideIndex].MinData
  1313. maxLimit = newData[sameSideIndex].MaxData
  1314. }else{
  1315. const limitMap = {
  1316. 0:['rightMin','rightMax'],
  1317. 1:['leftMin','leftMax'],
  1318. 2:['rightTwoMin','rightTwoMax']
  1319. }
  1320. if(limitMap[item.IsAxis]){
  1321. minLimit = axisLimitState[`${limitMap[item.IsAxis][0]}`]||0
  1322. maxLimit = axisLimitState[`${limitMap[item.IsAxis][1]}`]||0
  1323. }
  1324. }
  1325. // 设置y轴
  1326. if(item.IsAxis){
  1327. temYLeftArr.push(item)
  1328. }else{
  1329. temYRightArr.push(item)
  1330. }
  1331. const textZh = item.ConvertUnit||item.Unit
  1332. const textEn = item.ConvertEnUnit||item.UnitEn||item.ConvertUnit||item.Unit
  1333. let yItem={
  1334. ...basicYAxis,
  1335. IsAxis:item.IsAxis,
  1336. labels: {
  1337. formatter: (ctx) => {
  1338. return sameSideIndex !== index ? '' : e.ChartInfo.ChartType===3&&ExtraConfig.HeapWay==2?ctx.value+'%':ctx.value;
  1339. },
  1340. align: 'center',
  1341. x: [0,2].includes(item.IsAxis) ? 5 : -5,
  1342. style:{
  1343. ...chartTheme&&chartTheme.yAxisOptions.style
  1344. },
  1345. },
  1346. title: {
  1347. // text: sameSideIndex !== index ? '' : `${item.Unit}`,
  1348. text: textZh,
  1349. textZh:textZh, // 中文
  1350. // 中文不存在,无论英文有无都显示空
  1351. textEn:textZh?textEn||'英文单位':'', // 英文
  1352. align: 'high',
  1353. rotation: 0,
  1354. y: -15,
  1355. x: (item.IsAxis===0 && temYRightTwoIndex>-1) ? -newData[temYRightTwoIndex].Unit.length*12 : 0,
  1356. textAlign: item.IsAxis===1 ? 'left' : 'right',
  1357. reserveSpace: false,
  1358. style:{
  1359. ...chartTheme&&chartTheme.yAxisOptions.style
  1360. },
  1361. },
  1362. opposite: [0,2].includes(item.IsAxis),
  1363. reversed: item.IsOrder,
  1364. min: e.ChartInfo.ChartType===3&&ExtraConfig.HeapWay==2?null:Number(minLimit),
  1365. max: e.ChartInfo.ChartType===3&&ExtraConfig.HeapWay==2?null:Number(maxLimit),
  1366. tickWidth: sameSideIndex !== index ? 0 : 1,
  1367. visible: serie_yIndex === index && sameSideIndex ===index,
  1368. plotBands: setAxisPlotAreas(item.IsAxis),
  1369. plotLines: setAxisPlotLines(item.IsAxis),
  1370. chartEdbInfo:item//指标数据用于在保存时读取指标数据
  1371. }
  1372. yAxis.push(yItem)
  1373. if(item.DataList.length>0){
  1374. minAndMaxTimeTemArr.push(item.DataList[0].DataTimestamp)
  1375. minAndMaxTimeTemArr.push(item.DataList[item.DataList.length-1].DataTimestamp)
  1376. }
  1377. })
  1378. // 设置x轴
  1379. // 找出所有指标的最大和最小时间 分成6段
  1380. let minTime=Math.min.apply(null,minAndMaxTimeTemArr)
  1381. let maxTime=Math.max.apply(null,minAndMaxTimeTemArr)
  1382. const isLessThanOneYear = xTimeDiffer(minTime,maxTime,e.ChartInfo.DateType)
  1383. xAxis={
  1384. ...basicXAxis,
  1385. labels: {
  1386. formatter: function (ctx) {
  1387. return isLessThanOneYear
  1388. ? HighchartsFormat.dateFormat('%m/%d', ctx.value)
  1389. : HighchartsFormat.dateFormat('%y/%m', ctx.value);
  1390. },
  1391. style: {
  1392. ...chartTheme&&chartTheme.xAxisOptions.style
  1393. }
  1394. },
  1395. tickInterval:screen.value === 'phone'?((maxTime-minTime)/6)/(24*3600*1000)>30?(maxTime-minTime)/6:24*3600*1000*30:undefined,
  1396. plotBands: setAxisPlotAreas(3,'datetime'),
  1397. plotLines: setAxisPlotLines(3,'datetime')
  1398. }
  1399. yAxis.forEach(item=>{
  1400. if(item.IsAxis === 1){//左轴
  1401. axisLimitState.hasLeftAxis=true
  1402. if(!useSelfLimit){
  1403. axisLimitState.leftMin=data[temYLeftIndex].MinData
  1404. axisLimitState.leftMax=data[temYLeftIndex].MaxData
  1405. item.min=data[temYLeftIndex].MinData
  1406. item.max=data[temYLeftIndex].MaxData
  1407. }
  1408. }else if (item.IsAxis===2){ // 右2轴
  1409. axisLimitState.hasRightTwoAxis=true
  1410. if(!useSelfLimit){
  1411. axisLimitState.rightTwoMin=data[temYRightTwoIndex].MinData
  1412. axisLimitState.rightTwoMax=data[temYRightTwoIndex].MaxData
  1413. item.min=data[temYRightTwoIndex].MinData
  1414. item.max=data[temYRightTwoIndex].MaxData
  1415. }
  1416. }else{
  1417. axisLimitState.hasRightAxis=true
  1418. if(!useSelfLimit){
  1419. axisLimitState.rightMin=data[temYRightIndex].MinData
  1420. axisLimitState.rightMax=data[temYRightIndex].MaxData
  1421. item.min=data[temYRightIndex].MinData
  1422. item.max=data[temYRightIndex].MaxData
  1423. }
  1424. }
  1425. })
  1426. let options={
  1427. series,
  1428. xAxis:xAxis,
  1429. yAxis,
  1430. rangeSelector:{ enabled: false}
  1431. }
  1432. //面积图百分比tooltip
  1433. if(e.ChartInfo.ChartType===3&&ExtraConfig.HeapWay == 2) {
  1434. options.tooltip = {
  1435. split: false,
  1436. shared: true,
  1437. dateTimeLabelFormats: {
  1438. // 时间格式化字符
  1439. day: '%Y/%m/%d',
  1440. week: "%Y/%m",
  1441. month: '%Y/%m',
  1442. year: '%Y/%m',
  1443. },
  1444. xDateFormat:'%Y/%m/%d',
  1445. className:'chart-tooltips-box',
  1446. pointFormat: '<span style=\"color:{point.color}\">●</span><span>{series.name}</span>' +':<b>{point.percentage:.1f}%</b> ({point.y:,.1f})<br/>'
  1447. }
  1448. }
  1449. return options
  1450. }
  1451. /* 散点图 第一个指标值为x轴 第二个指标为y轴*/
  1452. function setScatterOptions(data){
  1453. axisLimitState.leftIndex=1
  1454. axisLimitState.rightIndex=-1
  1455. axisLimitState.rightTwoIndex=-1
  1456. const dataList=data.EdbInfoList
  1457. const { ChartInfo } = data;
  1458. /* 主题样式*/
  1459. const chartTheme = ChartInfo.ChartThemeStyle ? JSON.parse(ChartInfo.ChartThemeStyle) : null;
  1460. //上下限设置的是y轴,也就是第二个指标的值,改回来
  1461. axisLimitState.hasLeftAxis=true
  1462. /* axisLimitState.leftMin=Number(dataList[1].MinData)
  1463. axisLimitState.leftMax=Number(dataList[1].MaxData)
  1464. axisLimitData.leftMin=Number(dataList[1].MinData)
  1465. axisLimitData.leftMax=Number(dataList[1].MaxData) */
  1466. // 取2个指标中日期相同的数据
  1467. const real_data = [];
  1468. let tmpData_date = {};//用来取点对应的日期
  1469. let data1 = _.cloneDeep(dataList)[0].DataList || [];
  1470. let data2 = _.cloneDeep(dataList)[1].DataList || [];
  1471. data1.forEach((_item) => {
  1472. data2.forEach((_item2) => {
  1473. if(_item.DataTimestamp === _item2.DataTimestamp) {
  1474. //日期
  1475. let itemIndex =_item.Value + "_" +_item2.Value
  1476. if(tmpData_date[itemIndex]) {
  1477. tmpData_date[itemIndex].push( moment(_item.DataTimestamp).format('YYYY/MM/DD'))
  1478. } else {
  1479. tmpData_date[itemIndex] = [moment(_item.DataTimestamp).format('YYYY/MM/DD')]
  1480. }
  1481. //值
  1482. real_data.push({
  1483. x: _item.Value,
  1484. y: _item2.Value
  1485. })
  1486. }
  1487. })
  1488. })
  1489. real_data.sort((x,y) => x-y);
  1490. //悬浮窗 拼接日期 原始指标名称
  1491. let tooltip = {
  1492. formatter: function() {
  1493. 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>
  1494. ${dataList[0].EdbName}: <span style="font-weight: 600"> ${this.x}</span><br>
  1495. ${dataList[1].EdbName}: <span style="font-weight: 600"> ${this.y}</span>
  1496. `
  1497. },
  1498. // 中文
  1499. formatterCh: function() {
  1500. 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>
  1501. ${dataList[0].EdbName}: <span style="font-weight: 600"> ${this.x}</span><br>
  1502. ${dataList[1].EdbName}: <span style="font-weight: 600"> ${this.y}</span>
  1503. `
  1504. },
  1505. // 英文
  1506. formatterEn: function() {
  1507. let str1 = `${dataList[0].EdbNameEn}`
  1508. let str2 = `${dataList[1].EdbNameEn}`
  1509. 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>
  1510. ${str1}: <span style="font-weight: 600"> ${this.x}</span><br>
  1511. ${str2}: <span style="font-weight: 600"> ${this.y}</span>
  1512. `
  1513. }
  1514. }
  1515. const { IsOrder,ChartColor } = dataList[0];
  1516. //获取上下限
  1517. let minLimit = 0,maxLimit = 0
  1518. if(!useSelfLimit){
  1519. minLimit = data.ChartInfo.LeftMin||0;
  1520. maxLimit = data.ChartInfo.LeftMax||0;
  1521. }else{
  1522. minLimit = axisLimitState.leftMin||0
  1523. maxLimit = axisLimitState.leftMax||0
  1524. }
  1525. console.log('check limit',minLimit,maxLimit)
  1526. const textYZh = dataList[1].ConvertUnit||dataList[1].Unit
  1527. const textYEn = dataList[1].ConvertEnUnit||dataList[1].UnitEn||dataList[1].ConvertUnit||dataList[1].Unit
  1528. //y轴
  1529. let yAxis = {
  1530. title: {
  1531. text: `${textYZh}`,
  1532. textZh:textYZh,
  1533. textEn:textYZh?textYEn:'',
  1534. align: 'high',
  1535. rotation: 0,
  1536. y: -15,
  1537. x:0,
  1538. textAlign: 'left',
  1539. reserveSpace: false,
  1540. style:{
  1541. ...chartTheme&&chartTheme.yAxisOptions.style
  1542. },
  1543. },
  1544. labels: {
  1545. formatter: function (ctx) {
  1546. return ctx.value;
  1547. },
  1548. align: 'center',
  1549. style:{
  1550. ...chartTheme&&chartTheme.yAxisOptions.style
  1551. },
  1552. },
  1553. opposite: false,
  1554. reversed: IsOrder,
  1555. min: Number(minLimit),
  1556. max: Number(maxLimit),
  1557. tickWidth: 1,
  1558. tickLength: 5,
  1559. lineWidth: 1,
  1560. lineColor: '#bfbfbf',
  1561. tickColor: '#bfbfbf',
  1562. offset: 0,
  1563. visible: true,
  1564. gridLineWidth: 0,
  1565. tickPosition: 'inside',
  1566. endOnTick: false,
  1567. startOnTick: false,
  1568. showLastLabel: true,
  1569. tickPixelInterval: 50,
  1570. plotBands: setAxisPlotAreas(1),
  1571. plotLines: setAxisPlotLines(1)
  1572. }
  1573. //数据列
  1574. let series = {
  1575. data: [],
  1576. type: 'scatter',
  1577. name: `${ChartInfo.ChartName}${IsOrder ? '(逆序)' : ''}`,
  1578. nameZh:`${ChartInfo.ChartName}${IsOrder ? '(逆序)' : ''}`,
  1579. nameEn:ChartInfo.ChartNameEn?`${ChartInfo.ChartNameEn}${IsOrder ? '(reverse)' : ''}`:'',
  1580. color: ChartColor,
  1581. visible:true,
  1582. chartType: 'linear',
  1583. marker: {
  1584. radius: (chartTheme&&chartTheme.lineOptionList[0].radius)||5,
  1585. },
  1586. }
  1587. real_data.forEach(_ => {
  1588. series.data.push([_.x,_.y])
  1589. })
  1590. const textXZh = dataList[0].ConvertUnit||dataList[0].Unit
  1591. const textXEn = dataList[0].ConvertEnUnit||dataList[0].UnitEn||dataList[0].ConvertUnit||dataList[0].Unit
  1592. return {
  1593. title: {
  1594. text:''
  1595. },
  1596. series: [ series ],
  1597. yAxis,
  1598. xAxis: {
  1599. ...scatterXAxis,
  1600. title: {
  1601. text: `${textXZh}`,
  1602. textZh:textXZh,
  1603. textEn:textXZh?textXEn:'',
  1604. align: 'high',
  1605. rotation: 0,
  1606. x: 0,
  1607. offset: 20,
  1608. style: {
  1609. ...chartTheme&&chartTheme.xAxisOptions.style
  1610. },
  1611. },
  1612. labels: {
  1613. style: {
  1614. ...chartTheme&&chartTheme.xAxisOptions.style
  1615. }
  1616. },
  1617. },
  1618. tooltip
  1619. }
  1620. }
  1621. /* 奇怪柱形图 */
  1622. const barDateList = ref([]);//柱形图的绘图数据
  1623. const barXData = ref([]);//柱形图的x轴
  1624. const barEdbData = ref([]);//柱形图的表格数据 只用于取值
  1625. let axisLimitData={}
  1626. /* 奇怪柱状图 和其他逻辑无公用点 依赖数据为单独的数据
  1627. x轴为指标名称的柱形图 以日期作为series
  1628. */
  1629. function setBarChart (e){
  1630. let seriesData = [];
  1631. const data = _.cloneDeep(barDateList.value);
  1632. /* 主题样式*/
  1633. const chartTheme = e.ChartInfo.ChartThemeStyle ? JSON.parse(e.ChartInfo.ChartThemeStyle) : null;
  1634. //x轴
  1635. let xAxis = {
  1636. ...scatterXAxis,
  1637. categories: barXData.value,
  1638. tickWidth: 1,
  1639. labels: {
  1640. style: {
  1641. ...chartTheme&&chartTheme.xAxisOptions.style
  1642. }
  1643. }
  1644. }
  1645. const { leftMin,leftMax } = axisLimitState;
  1646. const textZh = e.ChartInfo?.Unit
  1647. const textEn = e.ChartInfo?.UnitEn||e.ChartInfo?.Unit
  1648. // console.log(leftMin,leftMax)
  1649. //y轴
  1650. let yAxis = {
  1651. ...basicYAxis,
  1652. title: {
  1653. text: textZh,
  1654. textZh: textZh,
  1655. textEn: textEn,
  1656. align: 'high',
  1657. rotation: 0,
  1658. y: -12,
  1659. x:0,
  1660. textAlign: 'left',
  1661. reserveSpace: false,
  1662. style:{
  1663. ...chartTheme&&chartTheme.yAxisOptions.style
  1664. },
  1665. },
  1666. labels: {
  1667. formatter: function (ctx) {
  1668. let val = ctx.value;
  1669. return val;
  1670. },
  1671. align: 'center',
  1672. style:{
  1673. ...chartTheme&&chartTheme.yAxisOptions.style
  1674. },
  1675. },
  1676. min: Number(leftMin),
  1677. max: Number(leftMax),
  1678. opposite: false,
  1679. tickWidth: 1,
  1680. plotBands: setAxisPlotAreas(1),
  1681. plotLines: setAxisPlotLines(1)
  1682. }
  1683. //数据列
  1684. data.forEach(item => {
  1685. let serie_item = {
  1686. data: item.Value,
  1687. type: 'column',
  1688. yAxis: 0,
  1689. name: item.Name || item.Date,
  1690. nameZh: item.Name || item.Date,
  1691. nameEn: item.Date,
  1692. color: item.Color,
  1693. chartType: 'linear',
  1694. visible:true,
  1695. };
  1696. seriesData.push(serie_item)
  1697. })
  1698. return {
  1699. title: {
  1700. text:''
  1701. },
  1702. plotOptions: {
  1703. column:{
  1704. stacking: null,
  1705. },
  1706. },
  1707. series: seriesData,
  1708. yAxis: [ yAxis ],
  1709. xAxis
  1710. }
  1711. }
  1712. /* 获取图表详情后赋值柱状图数据 */
  1713. function initBarData(data){
  1714. const { XEdbIdValue,YDataList,EdbInfoList,ChartInfo } = data;
  1715. let xData = XEdbIdValue.map(_ => EdbInfoList.find(edb => edb.EdbInfoId===_).EdbAliasName)
  1716. // console.log(xData)
  1717. axisLimitState.leftIndex=-1
  1718. axisLimitState.rightIndex=-1
  1719. axisLimitState.rightTwoIndex=-1
  1720. barDateList.value = YDataList;
  1721. barXData.value = xData;
  1722. barEdbData.value = EdbInfoList;
  1723. axisLimitState.hasLeftAxis=true
  1724. axisLimitState.leftMin=Number(ChartInfo.LeftMin)
  1725. axisLimitState.leftMax=Number(ChartInfo.LeftMax)
  1726. return setBarChart(data);
  1727. }
  1728. /* 商品价格曲线设置 绘图逻辑同奇怪柱形图*/
  1729. const commodityChartData = ref([]);//商品价格图的绘图数据
  1730. const commodityXData = ref([]);//商品价格图的x轴
  1731. const commodityEdbList = ref([]);//商品价格图的表格数据 只用于取值
  1732. /* 商品价格曲线设置 绘图逻辑同奇怪柱形图*/
  1733. const setCommodityChart = (leftMin,leftMax) => {
  1734. axisLimitState.leftIndex=-1
  1735. axisLimitState.rightIndex=-1
  1736. axisLimitState.rightTwoIndex=-1
  1737. /* 主题样式*/
  1738. const chartTheme = chartData.value.ChartInfo.ChartThemeStyle ? JSON.parse(chartData.value.ChartInfo.ChartThemeStyle) : null;
  1739. let seriesData = [];
  1740. const data = _.cloneDeep(commodityChartData.value);
  1741. console.log(data);
  1742. //x轴
  1743. let xAxis = {
  1744. ...scatterXAxis,
  1745. categories: commodityXData.value.filter(_=>_.IsHide===0).map(_ => _.Name),
  1746. tickWidth: 1,
  1747. labels: {
  1748. style: {
  1749. ...chartTheme&&chartTheme.xAxisOptions.style
  1750. }
  1751. }
  1752. }
  1753. //y轴
  1754. let yAxis = {
  1755. ...basicYAxis,
  1756. title: {
  1757. text: commodityEdbList.value[0].Unit,
  1758. textZh: commodityEdbList.value[0].Unit,
  1759. textEn: commodityEdbList.value[0].Unit?(commodityEdbList.value[0].UnitEn||'英文单位'):'',
  1760. align: 'high',
  1761. rotation: 0,
  1762. y: -15,
  1763. textAlign: 'left',
  1764. reserveSpace: false,
  1765. style:{
  1766. ...chartTheme&&chartTheme.yAxisOptions.style
  1767. },
  1768. },
  1769. labels: {
  1770. formatter: function (ctx) {
  1771. let val = ctx.value;
  1772. return val;
  1773. },
  1774. align: 'center',
  1775. style:{
  1776. ...chartTheme&&chartTheme.yAxisOptions.style
  1777. },
  1778. },
  1779. min: Number(leftMin),
  1780. max: Number(leftMax),
  1781. opposite: false,
  1782. tickWidth: 1,
  1783. }
  1784. //数据列
  1785. data.forEach((item,index) => {
  1786. //处理首或/尾全是无效数据的以null填充
  1787. let filterData = filterInvalidData(item)
  1788. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  1789. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  1790. let serie_item = {
  1791. data: filterData,
  1792. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || 'spline',
  1793. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  1794. yAxis: 0,
  1795. name: item.Name,
  1796. nameZh: item.Name,
  1797. nameEn: item.NameEn,
  1798. color: item.Color,
  1799. chartType: 'linear',
  1800. lineWidth: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 3,
  1801. visible: true,
  1802. marker: {
  1803. enabled: false
  1804. }
  1805. };
  1806. seriesData.push(serie_item)
  1807. })
  1808. //tooltip
  1809. let tooltip = {
  1810. formatter: function() {
  1811. const ctx = this;
  1812. let str = '';
  1813. ctx.points.forEach(item => {
  1814. let obj_item = data.find(_ => _.Name === item.series.name);
  1815. let index = commodityXData.value.findIndex(_ => _.Name === ctx.x);
  1816. // 合约显示
  1817. const haveContract=obj_item.XEdbInfoIdList[index]
  1818. if(haveContract){
  1819. // 利润曲线指标名
  1820. const isEdb=commodityEdbList.value.some(_=>_.EdbInfoId===haveContract)
  1821. let edb_name = chartData.value.ChartInfo.Source === 5
  1822. ? (isEdb? obj_item.NameList[index] : `${chartData.value.DataResp.ProfitName}(${obj_item.NameList[index]})`)
  1823. : commodityEdbList.value.find(_ => _.EdbInfoId === obj_item.XEdbInfoIdList[index]).EdbName;
  1824. str+=`<b>${ edb_name }</b>`
  1825. if(!obj_item.NoDataEdbList.includes(obj_item.XEdbInfoIdList[index])) {
  1826. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: ${item.y}<br>`
  1827. }else {
  1828. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: 无<br>`
  1829. }
  1830. }
  1831. })
  1832. return str||'无合约'
  1833. },
  1834. formatterCh: function() {
  1835. const ctx = this;
  1836. let str = '';
  1837. ctx.points.forEach(item => {
  1838. let obj_item = data.find(_ => _.Name === item.series.name);
  1839. let index = commodityXData.value.findIndex(_ => _.Name === ctx.x);
  1840. // 合约显示
  1841. const haveContract=obj_item.XEdbInfoIdList[index]
  1842. if(haveContract){
  1843. // 利润曲线指标名
  1844. const isEdb=commodityEdbList.value.some(_=>_.EdbInfoId===haveContract)
  1845. let edb_name = chartData.value.ChartInfo.Source === 5
  1846. ? (isEdb? obj_item.NameList[index] : `${chartData.value.DataResp.ProfitName}(${obj_item.NameList[index]})`)
  1847. : commodityEdbList.value.find(_ => _.EdbInfoId === obj_item.XEdbInfoIdList[index]).EdbName;
  1848. str+=`<b>${ edb_name }</b>`
  1849. if(!obj_item.NoDataEdbList.includes(obj_item.XEdbInfoIdList[index])) {
  1850. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: ${item.y}<br>`
  1851. }else {
  1852. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: 无<br>`
  1853. }
  1854. }
  1855. })
  1856. return str||'无合约'
  1857. },
  1858. formatterEn: function() {
  1859. const ctx = this;
  1860. let str = '';
  1861. ctx.points.forEach(item => {
  1862. let obj_item = data.find(_ => _.NameEn === item.series.name);
  1863. let index = commodityXData.value.findIndex(_ => _.NameEn === ctx.x);
  1864. // 合约显示
  1865. const haveContract=obj_item.XEdbInfoIdList[index]
  1866. if(haveContract){
  1867. // 利润曲线指标名
  1868. const isEdb=commodityEdbList.value.some(_=>_.EdbInfoId===haveContract)
  1869. let edb_name = chartData.value.ChartInfo.Source === 5
  1870. ? (isEdb? obj_item.NameList[index] : `${chartData.value.DataResp.ProfitNameEn}(${obj_item.NameList[index]})`)
  1871. : commodityEdbList.value.find(_ => _.EdbInfoId === obj_item.XEdbInfoIdList[index]).EdbNameEn;
  1872. str+=`<b>${ edb_name }</b>`
  1873. if(!obj_item.NoDataEdbList.includes(obj_item.XEdbInfoIdList[index])) {
  1874. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: ${item.y}<br>`
  1875. }else {
  1876. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: 无<br>`
  1877. }
  1878. }
  1879. })
  1880. return str||'无合约'
  1881. },
  1882. shared: true
  1883. }
  1884. // console.log(seriesData);
  1885. return {
  1886. title: {
  1887. text:''
  1888. },
  1889. series: seriesData,
  1890. yAxis: [ yAxis ],
  1891. xAxis,
  1892. tooltip
  1893. }
  1894. };
  1895. /* 处理无效数据为null */
  1896. function filterInvalidData(item){
  1897. let validateArr = item.XEdbInfoIdList.filter(_ =>!item.NoDataEdbList.includes(_));
  1898. let first_index = item.XEdbInfoIdList.findIndex(_ => _ === validateArr[0]);
  1899. let last_index = item.XEdbInfoIdList.findIndex(_ => _ === validateArr[validateArr.length-1]);
  1900. // console.log('first_index',first_index)
  1901. // console.log('last_index',last_index)
  1902. let arr = item.Value.map((item,index) => {
  1903. if(index < first_index || index > last_index) {
  1904. return null
  1905. }else {
  1906. return item
  1907. }
  1908. })
  1909. // 根据设置的x轴显示隐藏去除值
  1910. let temArr=[]
  1911. commodityXData.value.forEach((i,index)=>{
  1912. if(i.IsHide!==1){
  1913. temArr.push(arr[index])
  1914. }
  1915. })
  1916. return temArr;
  1917. }
  1918. function initCommodityData(data){
  1919. const { XDataList,YDataList,EdbInfoList,ChartInfo,DataResp } = data;
  1920. commodityEdbList.value = EdbInfoList;
  1921. commodityChartData.value = ChartInfo.Source===5?DataResp.YDataList:YDataList
  1922. commodityXData.value = ChartInfo.Source===5?DataResp.XDataList:XDataList
  1923. axisLimitState.hasLeftAxis=true
  1924. axisLimitState.leftMin=Number(ChartInfo.LeftMin)
  1925. axisLimitState.leftMax=Number(ChartInfo.LeftMax)
  1926. return setCommodityChart(ChartInfo.LeftMin,ChartInfo.LeftMax);
  1927. }
  1928. //相关性图表
  1929. function initRelevanceChart(data){
  1930. /* 主题样式*/
  1931. const chartTheme = data.ChartInfo.ChartThemeStyle ? JSON.parse(data.ChartInfo.ChartThemeStyle) : null;
  1932. axisLimitState.leftIndex=-1
  1933. axisLimitState.rightIndex=-1
  1934. axisLimitState.rightTwoIndex=-1
  1935. // 处理X轴
  1936. let xAxis={
  1937. categories: data.ChartInfo.Source===3?data.XEdbIdValue:data.DataResp.XDateTimeValue,
  1938. tickWidth: 1,
  1939. title: {
  1940. text: data.ChartInfo.Source===3 ?`期数(${data.CorrelationChartInfo.LeadUnit})` : null,
  1941. textZh:data.ChartInfo.Source===3 ? `期数(${data.CorrelationChartInfo.LeadUnit})`:null,
  1942. textEn:data.ChartInfo.Source===3 ? `stage(${relevanceUnitEnMap[data.CorrelationChartInfo.LeadUnit]})`:null,
  1943. align: 'high',
  1944. rotation: 0,
  1945. x: 0,
  1946. y:10,
  1947. offset: 20,
  1948. style: {
  1949. ...chartTheme&&chartTheme.xAxisOptions.style
  1950. }
  1951. },
  1952. labels: {
  1953. style: {
  1954. ...chartTheme&&chartTheme.xAxisOptions.style
  1955. }
  1956. },
  1957. tickInterval: 1,
  1958. offset:0,
  1959. tickmarkPlacement:'on'
  1960. }
  1961. // 处理Y轴
  1962. let yAxis={
  1963. ...basicYAxis,
  1964. title: {
  1965. text: '相关性系数',
  1966. textZh: '相关性系数',
  1967. textEn: 'Correlation coefficient',
  1968. align: 'high',
  1969. rotation: 0,
  1970. y: -15,
  1971. textAlign: 'left',
  1972. reserveSpace: false,
  1973. style:{
  1974. ...chartTheme&&chartTheme.yAxisOptions.style
  1975. },
  1976. },
  1977. labels: {
  1978. formatter: function (ctx) {
  1979. let val = ctx.value;
  1980. return val;
  1981. },
  1982. align: 'center',
  1983. style:{
  1984. ...chartTheme&&chartTheme.yAxisOptions.style
  1985. },
  1986. },
  1987. opposite: false,
  1988. tickWidth: 1,
  1989. }
  1990. //处理series
  1991. let seriesData=[]
  1992. data.YDataList.forEach((item,index)=>{
  1993. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  1994. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  1995. let serie_item = {
  1996. data: item.Value,
  1997. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || 'spline',
  1998. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  1999. yAxis: 0,
  2000. name: item.Name||data.ChartInfo.ChartName,
  2001. nameZh: item.Name||data.ChartInfo.ChartName,
  2002. nameEn: item.NameEn||data.ChartInfo.ChartNameEn,
  2003. color: item.Color,
  2004. chartType: 'linear',
  2005. lineWidth: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 3,
  2006. visible:true,
  2007. marker: {
  2008. enabled: false
  2009. }
  2010. };
  2011. seriesData.push(serie_item)
  2012. })
  2013. const { LeadValue,LeadUnit } = data.CorrelationChartInfo;
  2014. const { Source } = data.ChartInfo;
  2015. let tooltip = {
  2016. formatter: function() {
  2017. let str = `<p>相关性系数:${this.y.toFixed(4)}</p><br><p>领先${ Source===3 ?this.x+'期' : LeadValue+LeadUnit}</p>`
  2018. return str
  2019. },
  2020. formatterCh: function() {
  2021. let str = `<p>相关性系数:${this.y.toFixed(4)}</p><br><p>领先${ Source===3 ?this.x+'期' : LeadValue+LeadUnit}</p>`
  2022. return str
  2023. },
  2024. formatterEn: function() {
  2025. let str = `<p>Correlation coefficient:${this.y.toFixed(4)}</p><br><p>lead${ Source===3 ? this.x+'stage' : LeadValue+relevanceUnitEnMap[LeadUnit]}</p>`
  2026. return str
  2027. }
  2028. }
  2029. nextTick(()=>{
  2030. // if(data.ChartInfo.Source===3){
  2031. // const hEl=document.getElementById(RenderDomId.value)
  2032. // // console.log(hEl.offsetHeight);
  2033. // xAxis.offset=-(hEl.offsetHeight-98)/2
  2034. // }
  2035. options.value = {
  2036. isRelevanceChart:data.ChartInfo.Source===3,
  2037. title: {
  2038. text:''
  2039. },
  2040. series: seriesData,
  2041. yAxis: [yAxis] ,
  2042. xAxis:xAxis,
  2043. tooltip
  2044. }
  2045. ChartIns.update(options.value,true)
  2046. })
  2047. return {
  2048. isRelevanceChart:true,
  2049. title: {
  2050. text:''
  2051. },
  2052. series: seriesData,
  2053. yAxis: [yAxis] ,
  2054. xAxis:xAxis,
  2055. tooltip
  2056. }
  2057. }
  2058. /* 截面散点图设置 sectionScatterData */
  2059. function setSectionScatterChart({DataResp,ChartInfo}) {
  2060. axisLimitState.leftIndex=-1
  2061. axisLimitState.rightIndex=-1
  2062. axisLimitState.rightTwoIndex=-1
  2063. /* 主题样式*/
  2064. const chartTheme = ChartInfo.ChartThemeStyle ? JSON.parse(ChartInfo.ChartThemeStyle) : null;
  2065. const { DataList,XName,XNameEn,XUnitName,XUnitNameEn,YName,YNameEn,YUnitName,YUnitNameEn } = DataResp;
  2066. const leftMin=Number(DataResp.YMinValue)
  2067. const leftMax=Number(DataResp.YMaxValue)
  2068. const xMin=Number(DataResp.XMinValue)
  2069. const xMax=Number(DataResp.XMaxValue)
  2070. axisLimitState.hasLeftAxis=true
  2071. axisLimitState.hasXAxis=true
  2072. axisLimitState.leftMin=leftMin
  2073. axisLimitState.leftMax=leftMax
  2074. axisLimitState.xMin=xMin
  2075. axisLimitState.xMax=xMax
  2076. //y轴
  2077. let yAxis = {
  2078. ...basicYAxis,
  2079. title: {
  2080. text: YName,
  2081. textZh:YName,// 中文
  2082. textEn:YNameEn|| '',
  2083. style:{
  2084. ...chartTheme&&chartTheme.yAxisOptions.style
  2085. },
  2086. align: 'middle',
  2087. },
  2088. labels: {
  2089. style:{
  2090. ...chartTheme&&chartTheme.yAxisOptions.style
  2091. },
  2092. },
  2093. opposite: false,
  2094. reversed: false,
  2095. min: Number(leftMin),
  2096. max: Number(leftMax),
  2097. tickWidth: 1,
  2098. plotBands: setAxisPlotAreas(1),
  2099. plotLines: setAxisPlotLines(1)
  2100. }
  2101. //x轴
  2102. let xAxis = {
  2103. ...scatterXAxis,
  2104. title: {
  2105. text: XName,
  2106. textZh:XName,// 中文
  2107. textEn:XNameEn || '',
  2108. style: {
  2109. ...chartTheme&&chartTheme.xAxisOptions.style
  2110. },
  2111. align: 'middle',
  2112. },
  2113. labels: {
  2114. style:{
  2115. ...chartTheme&&chartTheme.xAxisOptions.style
  2116. },
  2117. },
  2118. min: Number(xMin),
  2119. max: Number(xMax),
  2120. plotBands: setAxisPlotAreas(3),
  2121. plotLines: setAxisPlotLines(3)
  2122. }
  2123. //数据列
  2124. let series = [];
  2125. DataList.forEach((item,index) => {
  2126. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  2127. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  2128. //数据列
  2129. let series_item = {
  2130. data: [],
  2131. type: 'scatter',
  2132. name: item.Name,
  2133. nameZh: item.Name,
  2134. nameEn: item.NameEn,
  2135. color: item.Color,
  2136. lineWidth: 0,
  2137. chartType: 'linear',
  2138. zIndex:1,
  2139. visible: true,
  2140. marker: {
  2141. radius: (chartTheme&&chartTheme.lineOptionList[lineIndex].radius)||5,
  2142. },
  2143. }
  2144. item.EdbInfoList.forEach(_ => {
  2145. series_item.data.push({
  2146. x: _.XValue,
  2147. y: _.YValue,
  2148. dataLabels: {
  2149. enabled: _.IsShow,
  2150. allowOverlap: true,
  2151. align: 'left',
  2152. format: _.Name,
  2153. formatZh: _.Name,
  2154. formatEn: _.NameEn
  2155. }
  2156. })
  2157. })
  2158. series.push(series_item);
  2159. //趋势线
  2160. if(item.ShowTrendLine) {
  2161. let trend_data = item.TrendLimitData.map((_,_index) => (
  2162. _index === item.TrendLimitData.length-1 ? {
  2163. x: _.X,
  2164. y: _.Y,
  2165. dataLabels: {
  2166. enabled: item.ShowRSquare || item.ShowFitEquation,
  2167. align: 'left',
  2168. color: item.Color,
  2169. x: 20,
  2170. y: 30,
  2171. zIndex: 9,
  2172. allowOverlap: true,
  2173. formatter: function(){
  2174. let tag = '';
  2175. item.ShowRSquare && item.ShowFitEquation
  2176. ? tag =`<span>${item.TrendLine}</span><br><span>R²=${item.RSquare}</span>`
  2177. : item.ShowRSquare && !item.ShowFitEquation
  2178. ? tag =`<span>R²=${item.RSquare}</span>`
  2179. : item.ShowFitEquation && !item.ShowRSquare
  2180. ? tag =`<span>${item.TrendLine}</span>`
  2181. : ''
  2182. return tag
  2183. }
  2184. }
  2185. } : {
  2186. x: _.X,
  2187. y: _.Y,
  2188. }
  2189. ))
  2190. let trend_item = {
  2191. data: trend_data,
  2192. type: 'spline',
  2193. linkedTo: ':previous',
  2194. color: item.Color,
  2195. lineWidth: 1,
  2196. chartType: 'linear',
  2197. enableMouseTracking: false,
  2198. dashStyle:'Dash',
  2199. zIndex: 2,
  2200. visible: true,
  2201. marker: {
  2202. enabled: false
  2203. }
  2204. }
  2205. series.push(trend_item)
  2206. }
  2207. })
  2208. let tooltip = {
  2209. formatter: function() {
  2210. let series_obj = DataList.find(_ => _.Name === this.series.name);
  2211. let ponit_obj = series_obj.EdbInfoList.find(_ => _.XValue ===this.x && _.YValue===this.y);
  2212. let str=`<b>${ ponit_obj.Name }</b>`;
  2213. str += `<br><span style="color:${this.color}">\u25CF</span>${ponit_obj.XName}: ${this.x} ${ponit_obj.XDate}<br>`;
  2214. str += `<span style="color:${this.color}">\u25CF</span>${ponit_obj.YName}: ${this.y} (${ponit_obj.YDate})`;
  2215. return str
  2216. },
  2217. formatterCh: function() {
  2218. let series_obj = DataList.find(_ => _.Name === this.series.name);
  2219. let ponit_obj = series_obj.EdbInfoList.find(_ => _.XValue ===this.x && _.YValue===this.y);
  2220. let str=`<b>${ ponit_obj.Name }</b>`;
  2221. str += `<br><span style="color:${this.color}">\u25CF</span>${ponit_obj.XName}: ${this.x} ${ponit_obj.XDate}<br>`;
  2222. str += `<span style="color:${this.color}">\u25CF</span>${ponit_obj.YName}: ${this.y} (${ponit_obj.YDate})`;
  2223. return str
  2224. },
  2225. formatterEn: function() {
  2226. let series_obj = DataList.find(_ => _.NameEn === this.series.name);
  2227. let ponit_obj = series_obj.EdbInfoList.find(_ => _.XValue ===this.x && _.YValue===this.y);
  2228. let str=`<b>${ ponit_obj.NameEn }</b>`;
  2229. str += `<br><span style="color:${this.color}">\u25CF</span>${ponit_obj.XNameEn}: ${this.x} ${ponit_obj.XDate}<br>`;
  2230. str += `<span style="color:${this.color}">\u25CF</span>${ponit_obj.YNameEn}: ${this.y} ${ponit_obj.YDate}`;
  2231. return str
  2232. }
  2233. }
  2234. return {
  2235. title: {
  2236. text:''
  2237. },
  2238. series,
  2239. yAxis: [yAxis],
  2240. xAxis,
  2241. tooltip
  2242. }
  2243. }
  2244. /* 跨品种分析 */
  2245. function setCrossVarietyChart({DataResp,EdbInfoList,ChartInfo}) {
  2246. axisLimitState.leftIndex=-1
  2247. axisLimitState.rightIndex=-1
  2248. axisLimitState.rightTwoIndex=-1
  2249. /* 主题样式*/
  2250. const chartTheme = ChartInfo.ChartThemeStyle ? JSON.parse(ChartInfo.ChartThemeStyle) : null;
  2251. const { DataList,XName,YName,XNameEn,YNameEn,XMaxValue,XMinValue,YMaxValue,YMinValue } = DataResp;
  2252. const {leftMin,leftMax,xMin,xMax} = axisLimitState;
  2253. //y轴
  2254. let yAxis = {
  2255. ...basicYAxis,
  2256. title: {
  2257. text: YName,
  2258. textCh:YName,// 中文
  2259. textEn:YNameEn||YName,
  2260. align: 'middle',
  2261. style: {
  2262. ...chartTheme&&chartTheme.xAxisOptions.style
  2263. }
  2264. },
  2265. labels: {
  2266. style: {
  2267. ...chartTheme&&chartTheme.xAxisOptions.style
  2268. }
  2269. },
  2270. opposite: false,
  2271. reversed: false,
  2272. min: Number(leftMin),
  2273. max: Number(leftMax),
  2274. tickWidth: 1,
  2275. }
  2276. // x轴
  2277. let xAxis = {
  2278. ...scatterXAxis,
  2279. title: {
  2280. text: XName,
  2281. textCh:XName,// 中文
  2282. textEn:XNameEn || XName,
  2283. align: 'middle',
  2284. style: {
  2285. ...chartTheme&&chartTheme.xAxisOptions.style
  2286. }
  2287. },
  2288. labels: {
  2289. style: {
  2290. ...chartTheme&&chartTheme.xAxisOptions.style
  2291. }
  2292. },
  2293. min: Number(xMin),
  2294. max: Number(xMax),
  2295. }
  2296. //数据列
  2297. let series = [];
  2298. const tagMap = { //标签对应文字
  2299. 1: '最新',
  2300. 3: 'Fix'
  2301. }
  2302. DataList.forEach(item => {
  2303. //数据列
  2304. let series_item = {
  2305. data: [],
  2306. type: 'scatter',
  2307. name: item.Name,
  2308. nameZh: item.Name,
  2309. nameEn: item.NameEn||item.Name,
  2310. color: item.Color,
  2311. lineWidth: 0,
  2312. chartType: 'linear',
  2313. zIndex:1
  2314. }
  2315. item.CoordinatePointData.forEach(_ => {
  2316. series_item.data.push({
  2317. x: _.X,
  2318. y: _.Y,
  2319. dataLabels: {
  2320. enabled: _.ShowTips===1,
  2321. allowOverlap: true,
  2322. align: 'left',
  2323. format: tagMap[_.DateType] || `-${_.DaysAgo}D`,
  2324. }
  2325. })
  2326. })
  2327. series.push(series_item);
  2328. })
  2329. let tooltip = {
  2330. formatter: function() {
  2331. let series_obj = DataList.find(_ => _.Name === this.series.name);
  2332. let ponit_obj = series_obj.CoordinatePointData.find(_ => _.X ===this.x && _.Y===this.y);
  2333. let xEdbInfo = EdbInfoList.find(_ => _.EdbInfoId===ponit_obj.XEdbInfoId);
  2334. let yEdbInfo = EdbInfoList.find(_ => _.EdbInfoId===ponit_obj.YEdbInfoId);
  2335. let str=`<b>${ this.series.name }</b>`;
  2336. str += `<br><span style="color:${this.color}">\u25CF</span>${xEdbInfo.EdbName}: ${this.x} ${ponit_obj.XDate}<br>`;
  2337. str += `<span style="color:${this.color}">\u25CF</span>${yEdbInfo.EdbName}: ${this.y} ${ponit_obj.YDate}`;
  2338. return str
  2339. },
  2340. formatterCh: function() {
  2341. let series_obj = DataList.find(_ => _.Name === this.series.name);
  2342. let ponit_obj = series_obj.CoordinatePointData.find(_ => _.X ===this.x && _.Y===this.y);
  2343. let xEdbInfo = EdbInfoList.find(_ => _.EdbInfoId===ponit_obj.XEdbInfoId);
  2344. let yEdbInfo = EdbInfoList.find(_ => _.EdbInfoId===ponit_obj.YEdbInfoId);
  2345. let str=`<b>${ this.series.name }</b>`;
  2346. str += `<br><span style="color:${this.color}">\u25CF</span>${xEdbInfo.EdbName}: ${this.x} ${ponit_obj.XDate}<br>`;
  2347. str += `<span style="color:${this.color}">\u25CF</span>${yEdbInfo.EdbName}: ${this.y} ${ponit_obj.YDate}`;
  2348. return str
  2349. },
  2350. formatterEn: function() {
  2351. let series_obj = DataList.find(_ => _.NameEn === this.series.name);
  2352. let ponit_obj = series_obj.CoordinatePointData.find(_ => _.X ===this.x && _.Y===this.y);
  2353. let xEdbInfo = EdbInfoList.find(_ => _.EdbInfoId===ponit_obj.XEdbInfoId);
  2354. let yEdbInfo = EdbInfoList.find(_ => _.EdbInfoId===ponit_obj.YEdbInfoId);
  2355. let str=`<b>${ this.series.name }</b>`;
  2356. str += `<br><span style="color:${this.color}">\u25CF</span>${xEdbInfo.EdbNameEn}: ${this.x} ${ponit_obj.XDate}<br>`;
  2357. str += `<span style="color:${this.color}">\u25CF</span>${yEdbInfo.EdbNameEn}: ${this.y} ${ponit_obj.YDate}`;
  2358. return str
  2359. }
  2360. }
  2361. return {
  2362. title: {
  2363. text:''
  2364. },
  2365. series,
  2366. yAxis: [yAxis],
  2367. xAxis,
  2368. tooltip
  2369. }
  2370. }
  2371. /* 雷达图 */
  2372. function setRadarChart({DataResp,EdbInfoList,ChartInfo}) {
  2373. axisLimitState.leftIndex=-1
  2374. axisLimitState.rightIndex=-1
  2375. axisLimitState.rightTwoIndex=-1
  2376. const { YDataList,XEdbIdValue } = DataResp;
  2377. let XDataList = EdbInfoList.filter(_ => XEdbIdValue.includes(_.EdbInfoId));
  2378. axisLimitState.hasLeftAxis=true
  2379. axisLimitState.leftMin=Number(ChartInfo.LeftMin)
  2380. axisLimitState.leftMax=Number(ChartInfo.LeftMax)
  2381. /* 主题样式*/
  2382. const chartTheme = ChartInfo.ChartThemeStyle ? JSON.parse(ChartInfo.ChartThemeStyle) : null;
  2383. //x轴
  2384. let xAxis = {
  2385. lineWidth: 0,
  2386. tickLength: 0,
  2387. tickmarkPlacement: 'on',
  2388. categories:XDataList.map(_ => _.EdbAliasName||_.EdbName),
  2389. labels: {
  2390. allowOverlap: true,
  2391. autoRotationLimit: 40,
  2392. style: {
  2393. ...chartTheme&&chartTheme.xAxisOptions.style
  2394. }
  2395. }
  2396. }
  2397. //y轴
  2398. let yAxis = [{
  2399. gridLineInterpolation: 'polygon',
  2400. gridLineWidth: 1,
  2401. lineWidth: 0,
  2402. endOnTick: false,
  2403. startOnTick: false,
  2404. showLastLabel: true,
  2405. // tickAmount:4,
  2406. title: {
  2407. text: ChartInfo.Unit,
  2408. textCh: ChartInfo.Unit,
  2409. textEn: ChartInfo.UnitEn,
  2410. align: 'high',
  2411. rotation: 0,
  2412. y: 5,
  2413. x:10,
  2414. textAlign: 'left',
  2415. reserveSpace: false,
  2416. style:{
  2417. ...chartTheme&&chartTheme.yAxisOptions.style
  2418. },
  2419. },
  2420. labels: {
  2421. allowOverlap: true,
  2422. style:{
  2423. ...chartTheme&&chartTheme.yAxisOptions.style
  2424. }
  2425. },
  2426. min: Number(ChartInfo.LeftMin),
  2427. max: Number(ChartInfo.LeftMax),
  2428. }]
  2429. //系列
  2430. let series = [];
  2431. YDataList.forEach((item,index) => {
  2432. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  2433. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  2434. let serie_item = {
  2435. name: item.Name || item.Date,
  2436. nameZh: item.Name || item.Date,
  2437. nameEn: item.Date,
  2438. data: item.Value,
  2439. pointPlacement: 'on',
  2440. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || 'line',
  2441. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  2442. yAxis: 0,
  2443. color: item.Color,
  2444. lineWidth: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 1,
  2445. chartType: 'linear'
  2446. };
  2447. series.push(serie_item)
  2448. })
  2449. return {
  2450. chart: {
  2451. ...chartDefaultOpts.chart,
  2452. ...chartTheme?.drawOption,
  2453. spacing: [2,10,2,10],
  2454. polar:true,
  2455. },
  2456. title: {
  2457. text:''
  2458. },
  2459. pane: {
  2460. size: '85%'
  2461. },
  2462. series,
  2463. yAxis,
  2464. xAxis
  2465. }
  2466. }
  2467. //获取RGBA的透明度
  2468. function parseRgbaColor(color='rgba(51, 51, 51, 1)'){
  2469. const arr = color.match(/(\d(\.\d+)?)+/g) || ['','','',1];
  2470. return parseFloat(arr[3]||1)
  2471. }
  2472. /* ----自定义上下限相关--- */
  2473. /* 计算y轴上下限 */
  2474. function calcYAxislimit(tableData=[],ChartInfo,DataResp={}){
  2475. //散点图单独处理
  2476. if(ChartInfo.ChartType===5){
  2477. if(tableData[1]){
  2478. axisLimitState.leftMin = tableData[1].MinData
  2479. axisLimitState.leftMax = tableData[1].MaxData
  2480. }
  2481. return
  2482. }
  2483. //分组
  2484. const leftData = tableData.filter(i => i.IsAxis === 1).map(i => [Number(i.MinData), Number(i.MaxData)])
  2485. const rightData = tableData.filter(i => !i.IsAxis).map(i => [Number(i.MinData), Number(i.MaxData)])
  2486. const rightTwoData = tableData.filter(i => i.IsAxis === 2).map(i => [Number(i.MinData), Number(i.MaxData)])
  2487. //计算最大最小值
  2488. if (leftData.length) {
  2489. const {
  2490. Max,
  2491. Min
  2492. } = calcLimit(leftData.flat())
  2493. axisLimitState.leftMin = Min
  2494. axisLimitState.leftMax = Max
  2495. }
  2496. if (rightData.length) {
  2497. const {
  2498. Max,
  2499. Min
  2500. } = calcLimit(rightData.flat())
  2501. axisLimitState.rightMin = Min
  2502. axisLimitState.rightMax = Max
  2503. }
  2504. if (rightTwoData.length) {
  2505. const {
  2506. Max,
  2507. Min
  2508. } = calcLimit(rightTwoData.flat())
  2509. axisLimitState.rightTwoMin = Min
  2510. axisLimitState.rightTwoMax = Max
  2511. }
  2512. //季节性图-右轴单独处理
  2513. if(ChartInfo.ChartType===2){
  2514. if(DataResp.RightAxis&&DataResp.RightAxis.IsAdd&&DataResp.RightAxis.IsShow){
  2515. if(DataResp.RightAxis.IndicatorType===1){
  2516. axisLimitState.rightMin = DataResp.RightAxis.EdbInfoList[0].MinData||0
  2517. axisLimitState.rightMax = DataResp.RightAxis.EdbInfoList[0].MaxData||0
  2518. }else{
  2519. axisLimitState.rightMin = tableData[1].MinData||0
  2520. axisLimitState.rightMax = tableData[1].MaxData||0
  2521. }
  2522. }
  2523. }
  2524. }
  2525. function calcLimit(arr) {
  2526. return {
  2527. Max: Math.max(...arr),
  2528. Min: Math.min(...arr)
  2529. }
  2530. }
  2531. //图表详情-设置图表上下限
  2532. function setLimitData({EdbInfoList,ChartInfo,DataResp}){
  2533. const {
  2534. //左右轴极值字段
  2535. LeftMin=0,LeftMax=0,
  2536. RightMin=0,RightMax=0,
  2537. Right2Min=0,Right2Max=0,
  2538. MinMaxSave
  2539. } = ChartInfo
  2540. if(MinMaxSave){
  2541. axisLimitState.leftMin = Number(LeftMin)
  2542. axisLimitState.leftMax = Number(LeftMax)
  2543. axisLimitState.rightMin = Number(RightMin)
  2544. axisLimitState.rightMax = Number(RightMax)
  2545. axisLimitState.rightTwoMin = Number(Right2Min)
  2546. axisLimitState.rightTwoMax = Number(Right2Max)
  2547. //若用户修改过,则检测轴的上下限是否为空,若为空,则需要计算对应轴的上下限
  2548. checkLimit(EdbInfoList,ChartInfo)
  2549. console.log('check',axisLimitState.leftMin,axisLimitState.leftMax)
  2550. }else{
  2551. calcYAxislimit(EdbInfoList,ChartInfo,DataResp?DataResp:{})
  2552. }
  2553. }
  2554. function checkLimit(tableData=[],ChartInfo){
  2555. //散点图单独处理
  2556. if(ChartInfo.ChartType===5){
  2557. if(tableData[1]){
  2558. if(Number(axisLimitState.leftMin)===0&&Number(axisLimitState.leftMax)===0){
  2559. axisLimitState.leftMin = tableData[1].MinData
  2560. axisLimitState.leftMax = tableData[1].MaxData
  2561. }
  2562. }
  2563. return
  2564. }
  2565. //若轴的上下限均为0,则不管用户有没有修改过,都重新赋值
  2566. if(Number(axisLimitState.leftMin)===0&&Number(axisLimitState.leftMax)===0){
  2567. const leftData = tableData.filter(i=>i.IsAxis===1).map(i=>[Number(i.MinData),Number(i.MaxData)])
  2568. if(leftData.length){
  2569. const {Max,Min} = calcLimit(leftData.flat())
  2570. axisLimitState.leftMin = Min
  2571. axisLimitState.leftMax = Max
  2572. }
  2573. }
  2574. if(Number(axisLimitState.rightMin)===0&&Number(axisLimitState.rightMax)===0){
  2575. const rightData = tableData.filter(i => !i.IsAxis).map(i=>[Number(i.MinData),Number(i.MaxData)])
  2576. if(rightData.length){
  2577. const {Max,Min} = calcLimit(rightData.flat())
  2578. axisLimitState.rightMin = Min
  2579. axisLimitState.rightMax = Max
  2580. }
  2581. }
  2582. if(Number(axisLimitState.rightTwoMin)===0&&Number(axisLimitState.rightTwoMax)===0){
  2583. const rightTwoData = tableData.filter(i=>i.IsAxis===2).map(i=>[Number(i.MinData),Number(i.MaxData)])
  2584. if(rightTwoData.length){
  2585. const {Max,Min} = calcLimit(rightTwoData.flat())
  2586. axisLimitState.rightTwoMin = Min
  2587. axisLimitState.rightTwoMax = Max
  2588. }
  2589. }
  2590. }
  2591. /*-------------------- */