mixins.js 71 KB

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