render.js 78 KB

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