index.vue 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628
  1. <!-- -->
  2. <template>
  3. <div class="chart-show">
  4. <header class="chart-header" @click="openNew">
  5. <span class="chart-title" @click.stop @dblclick="copyText">{{ language === 'ch'?chartInfo.ChartName: chartInfo.ChartNameEn}}</span>
  6. </header>
  7. <template v-if="haveData">
  8. <div
  9. class="chart-wrapper"
  10. id="chart-wrapper"
  11. v-loading="loading"
  12. element-loading-text="加载中..."
  13. >
  14. <chart :options="options" :chartId="chartInfo.ChartInfoId || 0" />
  15. <div class="mark"></div>
  16. </div>
  17. </template>
  18. <div class="chart-wrapper notfound" v-else>
  19. <i class="el-icon-warning"></i>哎吆,你的图飞了,赶快去找管理员救命吧~
  20. </div>
  21. <div class="bootom-source">
  22. <strong style="flex:1;" class="text_oneLine">source: <em> {{language === 'ch' ? chartInfo.ChartSource : chartInfo.ChartSourceEn}}</em></strong>
  23. <ul class="right-action" @click.stop>
  24. <li v-if="$route.query.source==='ybxcx'"><collectBtn/></li>
  25. <li @click="copyUrl" class="copy" v-if="isShare"><i class="el-icon-share"/>分享</li>
  26. <li @click="refreshChart" v-if="chartInfo.UniqueCode"><i class="el-icon-refresh"/>刷新</li>
  27. </ul>
  28. </div>
  29. </div>
  30. </template>
  31. <script lang="ts">
  32. import { defineComponent, reactive, toRefs, onMounted, ref } from 'vue';
  33. import { ElMessage } from 'element-plus';
  34. import _ from 'lodash';
  35. import { useRoute } from 'vue-router';
  36. import chart from '@/components/chart.vue';
  37. import { IState } from './typing';
  38. import { ChartApi } from '@/request/api';
  39. import { IChartType, IDataProps, ILunarItem, IParams, ISeasonDataItemProps } from '@/types';
  40. import Highcharts from 'highcharts';
  41. import { defaultOpts, seasonOptions } from '@/utils/chartOptions';
  42. import moment from 'moment';
  43. import collectBtn from './components/collectBtn.vue'
  44. // 散点x
  45. const scatterXAxis = {
  46. tickPosition: 'inside',
  47. lineColor: '#bfbfbf',
  48. tickColor: '#bfbfbf',
  49. tickLength:5,
  50. ordinal: false,
  51. type: 'linear',
  52. }
  53. //基础y轴
  54. const basicYAxis = {
  55. tickLength:5,
  56. lineWidth: 1,
  57. lineColor: '#bfbfbf',
  58. tickColor: '#bfbfbf',
  59. // offset: 0,
  60. visible: true,
  61. gridLineWidth: 0,
  62. tickPosition: 'inside',
  63. endOnTick: false,
  64. startOnTick: false,
  65. showLastLabel: true
  66. }
  67. export default defineComponent({
  68. components: {
  69. chart,
  70. collectBtn
  71. },
  72. setup() {
  73. const route = useRoute();
  74. const loading = ref(false);
  75. const haveData = ref(true);
  76. const code = ref(route.query.code);
  77. const isShare = ref(route.query.fromType === 'share');
  78. // 语言 中英文 ch en 默认中文
  79. const language = ref(route.query.lang || 'ch');
  80. const screen = ref(document.body.clientWidth < 1200 ? 'phone' : 'pc');
  81. const state = reactive<IState>({
  82. options: {},
  83. chartInfo: {},
  84. dataList: [],
  85. sourceName: '',
  86. /* 奇怪柱形图 */
  87. barDateList: [],//柱形图的绘图数据
  88. barXIdData: [],//柱形图的x轴id
  89. barEdbData: [],//柱形图的表格数据 只用于取值
  90. chartLimit: {},
  91. /* 商品价格曲线 */
  92. commodityChartData: [],
  93. commodityXData: [],
  94. commodityEdbList: [],
  95. /* 统计频率图 */
  96. statisticFrequencyData: {}
  97. });
  98. onMounted((): void => {
  99. getChartInfo();
  100. });
  101. // 打开新窗口
  102. const openNew = (): void => {
  103. window.open(window.location.href,'_blank');
  104. }
  105. /* 处理图表来源 只限第三方 */
  106. const dealSourceHandle = (): void => {
  107. // 取出第三方来源
  108. const arr = state.dataList.filter(item => item.EdbType === 1 && item.Source!== 9).map(item => ({
  109. key: item.Source,
  110. name: item.SourceName,
  111. })
  112. );
  113. let res_arr = arr.length ? _.uniqBy(arr,'key') : [];
  114. let str = '';
  115. res_arr.forEach((item: any) => {
  116. str += `${item.name}, `
  117. })
  118. state.sourceName = str;
  119. }
  120. /* 获取图表数据信息 */
  121. const getChartInfo = async (type='') => {
  122. if(!code.value) {
  123. haveData.value = false;
  124. return
  125. }
  126. loading.value = true;
  127. try {
  128. const { Data } = await ChartApi.getChart({
  129. UniqueCode: code.value || '',
  130. });
  131. loading.value = false;
  132. state.chartInfo = Data.ChartInfo;
  133. state.dataList = Data.ChartInfo.Source === 1 ? Data.EdbInfoList : [Data.EdbInfoList[0]];
  134. //处理英文研报英文设置不全就展示中文
  135. setLangFromEnReport();
  136. document.title = language.value==='ch'?Data.ChartInfo.ChartName:Data.ChartInfo.ChartNameEn;
  137. //eta图
  138. if(Data.ChartInfo.Source === 1) {
  139. const typeMap = {
  140. 7: initBarData,
  141. 10: initSectionScatterData
  142. }
  143. typeMap[state.chartInfo.ChartType] ? typeMap[state.chartInfo.ChartType](Data) : setOptions();
  144. }
  145. const sourceTypeMap = {
  146. 2: initCommodityData,
  147. 3: initRelevanceChartData,
  148. 4: initStatisticChartData,
  149. 5: initCommodityData,
  150. 6: initFittingEquation,
  151. 7: initStatisticChartData,
  152. 8: initStatisticChartData,
  153. 9: initStatisticChartData,
  154. }
  155. sourceTypeMap[Data.ChartInfo.Source] && sourceTypeMap[Data.ChartInfo.Source](Data);
  156. haveData.value = true;
  157. type === 'refresh' && ElMessage.success('刷新成功');
  158. }catch (e) {
  159. loading.value = false;
  160. haveData.value = false;
  161. }
  162. };
  163. /* 相关性图表 */
  164. const initRelevanceChartData=(data)=>{
  165. const relevanceUnitEnMap={
  166. '年': 'Year',
  167. '季': 'Season',
  168. '月': 'Month',
  169. '周': 'Week',
  170. '天': 'Day',
  171. }
  172. // 处理X轴
  173. let xAxis={
  174. categories: data.ChartInfo.Source===3 ? data.XEdbIdValue : data.DataResp.XDateTimeValue,
  175. tickWidth: 1,
  176. title: {
  177. text: data.ChartInfo.Source===3 ? (language.value=='ch'?`期数(${data.CorrelationChartInfo.LeadUnit})`:`stage(${relevanceUnitEnMap[data.CorrelationChartInfo.LeadUnit]})`):null,
  178. align: 'high',
  179. rotation: 0,
  180. x: 0,
  181. y:2,
  182. offset: 20,
  183. },
  184. tickInterval: 1,
  185. offset:0,
  186. tickmarkPlacement:'on'
  187. }
  188. // 处理Y轴
  189. let yAxis={
  190. ...basicYAxis,
  191. title: {
  192. text: language.value=='ch'?'相关性系数':'Correlation coefficient',
  193. align: 'high',
  194. rotation: 0,
  195. y: -15,
  196. offset: 0,
  197. },
  198. labels: {
  199. formatter: function (ctx) {
  200. let val = ctx.value;
  201. return val;
  202. },
  203. align: 'center',
  204. },
  205. // min: -1,
  206. // max: 1,
  207. opposite: false,
  208. tickWidth: 1,
  209. // tickInterval:0.2,
  210. }
  211. //处理series
  212. let seriesData=[]
  213. data.YDataList.forEach(item=>{
  214. let serie_item = {
  215. data: item.Value,
  216. type: 'spline',
  217. yAxis: 0,
  218. name: language.value=='ch'?data.ChartInfo.ChartName:data.ChartInfo.ChartNameEn,
  219. color: item.Color,
  220. chartType: 'linear',
  221. lineWidth: 3,
  222. marker: {
  223. enabled: false
  224. }
  225. };
  226. seriesData.push(serie_item)
  227. })
  228. const { LeadValue,LeadUnit } = data.CorrelationChartInfo;
  229. let tooltip = {
  230. formatter: function() {
  231. const that:any = this;
  232. let str='';
  233. if(language.value=='ch'){
  234. str = `<p>相关性系数:${that.y.toFixed(4)}</p><br><p>领先${ data.ChartInfo.Source===3 ?that.x+'期' : LeadValue+LeadUnit}</p>`
  235. }else{
  236. str = `<p>Correlation coefficient:${that.y.toFixed(4)}</p><br><p>lead${ data.ChartInfo.Source===3 ? that.x+'stage' : LeadValue+relevanceUnitEnMap[LeadUnit]}</p>`
  237. }
  238. return str
  239. },
  240. }
  241. state.options = {
  242. isRelevanceChart:data.ChartInfo.Source===3,
  243. title: {
  244. text:'',
  245. },
  246. series: seriesData,
  247. yAxis: [yAxis] ,
  248. xAxis:xAxis,
  249. tooltip
  250. }
  251. }
  252. /* 拟合方程曲线 */
  253. const initFittingEquation = (data) => {
  254. state.dataList = [data.DataResp];
  255. setDefaultLineOptions();
  256. }
  257. /* 散点截面图 */
  258. const sectionScatterData = ref<any>({});
  259. const initSectionScatterData = (data: { DataResp:any,EdbInfoList:any[] }) => {
  260. sectionScatterData.value = data.DataResp;
  261. state.chartLimit.min=Number(data.DataResp.YMinValue)
  262. state.chartLimit.max=Number(data.DataResp.YMaxValue)
  263. state.chartLimit.x_min=Number(data.DataResp.XMinValue)
  264. state.chartLimit.x_max=Number(data.DataResp.XMaxValue)
  265. //校验英文名称是否完整
  266. if(route.query.fromPage === 'en' && language.value==='en') {
  267. const { XNameEn,XUnitNameEn,YNameEn,YUnitNameEn,DataList } = data.DataResp;
  268. let isAllEn = true;
  269. if(!XNameEn || !XUnitNameEn || !YNameEn || !YUnitNameEn) isAllEn = false;
  270. if(DataList.some(_ => !_.NameEn)) isAllEn = false;
  271. console.log(isAllEn)
  272. language.value = isAllEn ? 'en' : 'ch';
  273. }
  274. setSectionScatterChart()
  275. }
  276. /* 截面散点图设置 sectionScatterData */
  277. const setSectionScatterChart = () => {
  278. const { chartLimit } = state;
  279. const { DataList,XName,XNameEn,XUnitName,XUnitNameEn,YName,YNameEn,YUnitName,YUnitNameEn } = sectionScatterData.value;
  280. const { min,max,x_min,x_max } = chartLimit;
  281. //y轴
  282. let yAxis = {
  283. ...basicYAxis,
  284. title: {
  285. text: language.value === 'ch' ? YName : YNameEn,
  286. align: 'middle',
  287. },
  288. opposite: false,
  289. reversed: false,
  290. min: Number(min),
  291. max: Number(max),
  292. tickWidth: 1,
  293. }
  294. //x轴
  295. let xAxis = {
  296. ...scatterXAxis,
  297. title: {
  298. text: language.value === 'ch' ? XName : XNameEn,
  299. align: 'middle',
  300. },
  301. min: Number(x_min),
  302. max: Number(x_max),
  303. }
  304. //数据列
  305. let series: any[] = [];
  306. DataList.forEach(item => {
  307. //数据列
  308. let series_item = {
  309. data: [] as any[],
  310. type: 'scatter',
  311. name: language.value === 'ch' ? item.Name : item.NameEn,
  312. color: item.Color,
  313. lineWidth: 0,
  314. chartType: 'linear',
  315. zIndex:1,
  316. visible: true
  317. }
  318. item.EdbInfoList.forEach(_ => {
  319. series_item.data.push({
  320. x: _.XValue,
  321. y: _.YValue,
  322. dataLabels: {
  323. enabled: _.IsShow,
  324. allowOverlap: true,
  325. align: 'left',
  326. format: language.value === 'ch' ? _.Name : _.NameEn
  327. }
  328. })
  329. })
  330. series.push(series_item);
  331. //趋势线
  332. if(item.ShowTrendLine) {
  333. let trend_data = item.TrendLimitData.map((_,_index) => (
  334. _index === item.TrendLimitData.length-1 ? {
  335. x: _.X,
  336. y: _.Y,
  337. dataLabels: {
  338. enabled: item.ShowRSquare || item.ShowFitEquation,
  339. align: 'left',
  340. color: '#666',
  341. x: 20,
  342. y: 30,
  343. zIndex: 9,
  344. allowOverlap: true,
  345. formatter: function(){
  346. let tag = '';
  347. item.ShowRSquare && item.ShowFitEquation
  348. ? tag =`<span>${item.TrendLine}</span><br><span>R²=${item.RSquare}</span>`
  349. : item.ShowRSquare && !item.ShowFitEquation
  350. ? tag =`<span>R²=${item.RSquare}</span>`
  351. : item.ShowFitEquation && !item.ShowRSquare
  352. ? tag =`<span>${item.TrendLine}</span>`
  353. : ''
  354. return tag
  355. }
  356. }
  357. } : {
  358. x: _.X,
  359. y: _.Y,
  360. }
  361. ))
  362. let trend_item = {
  363. data: trend_data,
  364. type: 'spline',
  365. linkedTo: ':previous',
  366. color: item.Color,
  367. lineWidth: 1,
  368. chartType: 'linear',
  369. enableMouseTracking: false,
  370. dashStyle:'Dash',
  371. zIndex: 2,
  372. visible: true,
  373. marker: {
  374. enabled: false
  375. }
  376. }
  377. series.push(trend_item)
  378. }
  379. })
  380. let tooltip = {
  381. formatter: function() {
  382. const that:any = this;
  383. let str = '';
  384. if(language.value === 'ch') {
  385. let series_obj = DataList.find(_ => _.Name === that.series.name);
  386. let ponit_obj = series_obj.EdbInfoList.find(_ => _.XValue ===that.x && _.YValue===that.y);
  387. str=`<b>${ ponit_obj.Name }</b>`;
  388. str += `<br><span style="color:${that.color}">\u25CF</span>${ponit_obj.XName}: ${that.x} ${ponit_obj.XDate}<br>`;
  389. str += `<span style="color:${that.color}">\u25CF</span>${ponit_obj.YName}: ${that.y} ${ponit_obj.YDate}`;
  390. }else {
  391. let series_obj = DataList.find(_ => _.NameEn === that.series.name);
  392. let ponit_obj = series_obj.EdbInfoList.find(_ => _.XValue ===that.x && _.YValue===that.y);
  393. str=`<b>${ ponit_obj.NameEn }</b>`;
  394. str += `<br><span style="color:${that.color}">\u25CF</span>${ponit_obj.XNameEn}: ${that.x} ${ponit_obj.XDate}<br>`;
  395. str += `<span style="color:${that.color}">\u25CF</span>${ponit_obj.YNameEn}: ${that.y} ${ponit_obj.YDate}`;
  396. }
  397. return str
  398. }
  399. }
  400. state.options = {
  401. title: {
  402. text:''
  403. },
  404. series,
  405. yAxis: [yAxis],
  406. xAxis,
  407. tooltip
  408. }
  409. }
  410. const correlationChartInfo = ref<any>({});
  411. /* 统计特征 标准差 百分比 频率 滚动相关性*/
  412. const initStatisticChartData = (data: { DataResp:any,ChartInfo:any,CorrelationChartInfo:any }) => {
  413. if(data.ChartInfo.Source === 9) { //频率图
  414. state.statisticFrequencyData = data.DataResp;
  415. setStatisticFrequency();
  416. }else {
  417. state.dataList = [data.DataResp];
  418. if(data.ChartInfo.Source === 4) correlationChartInfo.value = data.CorrelationChartInfo;
  419. setDefaultLineOptions();
  420. }
  421. }
  422. /* 统计频率图 */
  423. const setStatisticFrequency = () => {
  424. const { DataList,LeftMaxValue,LeftMinValue,RightMaxValue,RightMinValue } = state.statisticFrequencyData;
  425. let xAxis = {
  426. ...scatterXAxis,
  427. tickWidth: 1,
  428. title: {
  429. text: ``,
  430. align: 'high',
  431. rotation: 0,
  432. x: 0,
  433. offset: 20,
  434. }
  435. }
  436. //y和系列
  437. let yAxis:any[] = [],series:any[] = [];
  438. DataList.forEach((item,index) => {
  439. let y_item = {
  440. ...basicYAxis,
  441. title: {
  442. text: language.value === 'ch' ? item.Unit : item.UnitEn,
  443. align: 'high',
  444. rotation: 0,
  445. y: -15,
  446. offset: 0,
  447. },
  448. opposite: item.IsAxis===1?false:true,
  449. min: index===0? Number(LeftMinValue):Number(RightMinValue),
  450. max: index===0? Number(LeftMaxValue):Number(RightMaxValue),
  451. tickWidth: 1,
  452. }
  453. let series_item = {
  454. data: item.Value.map(_ =>[_.X,_.Y]),
  455. type: 'spline',
  456. yAxis: index,
  457. name: language.value === 'ch' ? item.Name : item.NameEn,
  458. color: item.Color,
  459. lineWidth: 3,
  460. chartType: 'linear',
  461. zIndex:1
  462. }
  463. series.push(series_item);
  464. yAxis.push(y_item)
  465. })
  466. let tooltip = {
  467. formatter: function() {
  468. let that:any = this;
  469. let xList = DataList[0].Value.map(_ =>_.X);
  470. let step = xList[1]-xList[0];
  471. let data_interval = `[${Number(that.x).toFixed(2)},${Number(that.x+step).toFixed(2)}]`;
  472. let str=`<b>${ data_interval }</b>`;
  473. that.points.forEach(item => {
  474. str += `<br><span style="color:${item.color}">\u25CF</span>${item.series.name}: ${item.y}%`
  475. })
  476. return str
  477. },
  478. shared: true
  479. }
  480. state.options = {
  481. title: {
  482. text:''
  483. },
  484. tooltip,
  485. series,
  486. yAxis,
  487. xAxis
  488. }
  489. }
  490. //处理英文研报的图表英文设置不全的情况
  491. const setLangFromEnReport = () => {
  492. //来源于英文研报
  493. if(route.query.fromPage !== 'en') return
  494. let is_name_en = state.chartInfo.ChartNameEn ? true : false;//名称是否有英文
  495. let is_target_en = [2,9].includes(state.chartInfo.ChartType) ? true : state.dataList.every(_ => _.EdbNameEn);//指标是否有英文
  496. console.log(is_name_en,is_target_en)
  497. language.value = (is_name_en && is_target_en) ? 'en' : 'ch';
  498. }
  499. // 曲线图x轴显示计算年限差 >1年 显示年/月 <=1 显示月/日
  500. const xTimeDiffer = () => {
  501. const end_date = state.chartInfo.DateType === 5
  502. ? state.chartInfo.EndDate
  503. : state.chartInfo.DateType === 6
  504. ? new Date()
  505. : '';
  506. //年限差
  507. const year_differ = moment(end_date).diff(
  508. moment(state.chartInfo.StartDate),
  509. 'years',
  510. true
  511. );
  512. // console.log(year_differ)
  513. if ([5, 6].includes(state.chartInfo.DateType) && year_differ <= 1) {
  514. return true
  515. } else {
  516. return false
  517. }
  518. }
  519. /* 曲线图 */
  520. const setDefaultLineOptions = () => {
  521. const { dataList,chartInfo } = state;
  522. //拼接标题 数据列
  523. let data = [] as any[],ydata = [] as any[],minTimeArr: number[] = [],maxTimeArr: number[] = [];
  524. let rightTwoIndex = dataList.findIndex(item => item.IsAxis ===2);
  525. // const chartData = _.cloneDeep(dataList);
  526. //有右二轴时排个序 按照左 右 右2的顺序
  527. let chartData = dataList.some(_ =>_.IsAxis===2) ? changeEdbOrder(dataList) : _.cloneDeep(dataList);
  528. chartData.forEach((item:IDataProps ,index:number) => {
  529. //轴位置值相同的下标
  530. let sameSideIndex = chartData.findIndex(
  531. (i:IDataProps) => i.IsAxis === item.IsAxis
  532. );
  533. //y轴
  534. let textEn = item.Unit?item.UnitEn:''
  535. let yItem = {
  536. ...basicYAxis,
  537. labels: {
  538. formatter: function (ctx: any) {
  539. let val = ctx.value;
  540. return sameSideIndex !== index ? '' : val;
  541. },
  542. align: 'center',
  543. x: [0,2].includes(item.IsAxis) ? 5 : -5,
  544. style: {
  545. fontSize: '10px',
  546. },
  547. },
  548. title: {
  549. text:language.value=='ch'?sameSideIndex !== index ? '' : `${item.Unit}`:textEn,
  550. // text: null,
  551. align: 'high',
  552. rotation: 0,
  553. y: -15,
  554. x: (item.IsAxis===0 && rightTwoIndex>-1) ? -chartData[rightTwoIndex].Unit.length*12 : 0,
  555. textAlign: item.IsAxis===1 ? 'left' : 'right',
  556. reserveSpace: false
  557. },
  558. opposite: [0,2].includes(item.IsAxis),
  559. reversed: item.IsOrder,
  560. min: Number(chartData[sameSideIndex].MinData),
  561. max: Number(chartData[sameSideIndex].MaxData),
  562. tickWidth: sameSideIndex !== index ? 0 : 1,
  563. visible: sameSideIndex === index
  564. }
  565. // //拼接标题 判断相同指标名称拼接来源
  566. let dynamic_title = item.EdbName;
  567. let dynamic_arr = chartData.filter(
  568. (item: IDataProps) => dynamic_title === item.EdbName
  569. );
  570. // 拼接配置 IsAxis左轴1 右轴0 IsOrder正序false 逆序true EdbInfoType是否是领先指标
  571. let dynamic_tag = concatDynamicTag(item)
  572. // 英文后缀
  573. let dynamic_tag_en = concatDynamicTag(item,'en')
  574. //数据列
  575. let nameCh:String = dynamic_arr.length > 1
  576. ? `${item.EdbName}(${item.SourceName})${dynamic_tag}`
  577. : `${item.EdbName}${dynamic_tag}`
  578. let nameEn:String=item.EdbNameEn?`${item.EdbNameEn}${dynamic_tag_en}`:''
  579. let name :String=language.value == 'ch'?nameCh:nameEn
  580. //预测指标配置
  581. let predict_params = item.EdbInfoCategoryType === 1 ? getPredictParams(item) : {};
  582. let obj = {
  583. data: [] as any[],
  584. type: 'spline',
  585. yAxis: sameSideIndex,
  586. name,
  587. color: item.ChartColor,
  588. lineWidth: Number(item.ChartWidth),
  589. ...predict_params
  590. };
  591. item.DataList = item.DataList || []
  592. for (let i of item.DataList) {
  593. obj.data.push([i.DataTimestamp, i.Value]);
  594. }
  595. if(item.DataList.length){
  596. minTimeArr.push(item.DataList[0].DataTimestamp)
  597. maxTimeArr.push(item.DataList[item.DataList.length-1].DataTimestamp)
  598. }
  599. data.push(obj);
  600. ydata.push(yItem);
  601. })
  602. // 范围为1年内 x轴显示为月/日 否则默认年/月
  603. let xAxis:any = {};
  604. const bool_time:boolean = xTimeDiffer();
  605. let minTime: number=Math.min(...minTimeArr);
  606. let maxTime=Math.max(...maxTimeArr);
  607. let step = setXaxisStep(maxTime-minTime);
  608. xAxis = bool_time ? {
  609. ...defaultOpts.xAxis,
  610. tickInterval: screen.value === 'phone' ? step : undefined,
  611. labels: {
  612. formatter: function (ctx: any) {
  613. return Highcharts.dateFormat('%m/%d', ctx.value);
  614. },
  615. style: {
  616. fontSize: '10px',
  617. },
  618. }
  619. } : {
  620. ...defaultOpts.xAxis,
  621. tickInterval: screen.value === 'phone' ? step : undefined,
  622. labels: {
  623. style: {
  624. fontSize: '10px',
  625. },
  626. },
  627. }
  628. state.options = {
  629. series: data,
  630. yAxis: ydata,
  631. xAxis
  632. };
  633. //滚动相关性独立tooltip
  634. if(chartInfo.Source === 4) {
  635. const relevanceUnitEnMap={
  636. '年': 'Year',
  637. '季': 'Season',
  638. '月': 'Month',
  639. '周': 'Week',
  640. '天': 'Day',
  641. }
  642. const { LeadValue,LeadUnit } = correlationChartInfo.value;
  643. state.options.tooltip = {
  644. formatter: function() {
  645. let that:any = this;
  646. let str = '';
  647. if(language.value=='ch'){
  648. str = `${Highcharts.dateFormat('%Y/%m/%d',that.x)}<br><p>相关性系数:${that.y.toFixed(4)}</p><br><p>领先${LeadValue+LeadUnit}</p>`
  649. }else{
  650. str = `${Highcharts.dateFormat('%Y/%m/%d',that.x)}<br><p>Correlation coefficient:${that.y.toFixed(4)}</p><br><p>lead${LeadValue+relevanceUnitEnMap[LeadUnit]}</p>`
  651. }
  652. return str
  653. },
  654. }
  655. }
  656. }
  657. /* 设置x轴步长 刻度数量多一点 */
  658. const setXaxisStep = (timestamp: number) => {
  659. // return timestamp / 6 < 24 * 3600 * 1000 * 30 ? 24 * 3600 * 1000 * 30 : timestamp / 6;
  660. return timestamp / 6;
  661. }
  662. /* 指标顺序调整 IsAxis: 0右轴 1左轴 2右2*/
  663. const changeEdbOrder = (data: any[]) => {
  664. // 左轴指标
  665. let left_edbs = data.filter(_ => _.IsAxis===1);
  666. //右轴指标
  667. let right_edbs = data.filter(_ => !_.IsAxis);
  668. // 右2轴指标
  669. let right_two_edbs = data.filter(_ => _.IsAxis === 2);
  670. // 按 左 右 右2顺序排列
  671. return [left_edbs,right_edbs,right_two_edbs].flat(Infinity);
  672. }
  673. /* 堆叠图/组合图设置
  674. 本来和曲线图逻辑基本一致兼容下即可 为了以后便于维护和阅读还是拆开写吧
  675. */
  676. const setStackOrCombinChart = () => {
  677. const { dataList,chartInfo } = state;
  678. //拼接标题 数据列
  679. let data = [] as any[],ydata = [] as any[],minTimeArr: number[] = [],maxTimeArr: number[] = [];
  680. // const chartData = _.cloneDeep(dataList);
  681. //有右二轴时排个序 按照左 右 右2的顺序
  682. let chartData = dataList.some(_ =>_.IsAxis===2) ? changeEdbOrder(dataList) : _.cloneDeep(dataList);
  683. //支持的图表类型
  684. const chartTypeMap: IChartType = {
  685. 3: 'areaspline',
  686. 4: 'column',
  687. 6: ''
  688. };
  689. let chartStyle = chartTypeMap[chartInfo.ChartType];
  690. chartData.forEach((item:IDataProps ,index:number) => {
  691. //轴位置值相同的下标
  692. let sameSideIndex = chartData.findIndex(
  693. (i:IDataProps) => i.IsAxis === item.IsAxis
  694. );
  695. //堆叠图的yAxis必须一致 数据列所对应的y轴
  696. let serie_yIndex = index;
  697. if([3,4].includes(chartInfo.ChartType)) {
  698. // 类型为堆叠图时公用第一个指标y轴
  699. serie_yIndex = 0;
  700. } else if(chartInfo.ChartType ===6 && ['areaspline','column'].includes(item.ChartStyle)) {
  701. // 组合图找第一个堆叠柱状或面积的作为公用
  702. serie_yIndex = chartData.findIndex((i:IDataProps) => i.ChartStyle === item.ChartStyle);
  703. }
  704. //数据对应的y轴是公用轴则配置也共享
  705. item.IsAxis = serie_yIndex === index ? item.IsAxis : chartData[serie_yIndex].IsAxis;
  706. item.IsOrder = serie_yIndex === index ? item.IsOrder : chartData[serie_yIndex].IsOrder;
  707. // 右2轴下标
  708. let rightTwoIndex = [3,4].includes(chartInfo.ChartType)
  709. ? -1
  710. : dataList.findIndex(item => item.IsAxis===2);
  711. //y轴
  712. let textEn = item.Unit?item.UnitEn:''
  713. let yItem = {
  714. ...basicYAxis,
  715. labels: {
  716. formatter: function (ctx: any) {
  717. let val = ctx.value;
  718. return sameSideIndex !== index ? '' : val;
  719. },
  720. align: 'center',
  721. x: [0,2].includes(item.IsAxis) ? 5 : -5,
  722. style: {
  723. fontSize: '10px',
  724. },
  725. },
  726. title: {
  727. text:language.value=='ch'?sameSideIndex !== index ? '' : `${item.Unit}`:textEn,
  728. // text: null,
  729. align: 'high',
  730. rotation: 0,
  731. y: -15,
  732. x: (item.IsAxis===0 && rightTwoIndex>-1) ? -chartData[rightTwoIndex].Unit.length*12 : 0,
  733. textAlign: item.IsAxis===1 ? 'left' : 'right',
  734. reserveSpace: false
  735. },
  736. opposite: [0,2].includes(item.IsAxis),
  737. reversed: item.IsOrder,
  738. min: Number(chartData[sameSideIndex].MinData),
  739. max: Number(chartData[sameSideIndex].MaxData),
  740. tickWidth: sameSideIndex !== index ? 0 : 1,
  741. visible: serie_yIndex === index && sameSideIndex ===index
  742. }
  743. // //拼接标题 判断相同指标名称拼接来源
  744. let dynamic_title = item.EdbName;
  745. let dynamic_arr = chartData.filter(
  746. (item: IDataProps) => dynamic_title === item.EdbName
  747. );
  748. // 拼接配置 IsAxis左轴1 右轴0 IsOrder正序false 逆序true EdbInfoType是否是领先指标
  749. let dynamic_tag = concatDynamicTag(item)
  750. // 英文后缀
  751. let dynamic_tag_en = concatDynamicTag(item,'en')
  752. //数据列
  753. let nameCh:String = dynamic_arr.length > 1
  754. ? `${item.EdbName}(${item.SourceName})${dynamic_tag}`
  755. : `${item.EdbName}${dynamic_tag}`
  756. let nameEn:String=item.EdbNameEn?`${item.EdbNameEn}${dynamic_tag_en}`:''
  757. let name :String=language.value == 'ch'?nameCh:nameEn
  758. //预测指标配置
  759. let predict_params = item.EdbInfoCategoryType === 1 ? getPredictParams(item,chartStyle) : {};
  760. let obj = {
  761. data: [] as any[],
  762. type: chartStyle || item.ChartStyle,
  763. yAxis: serie_yIndex,
  764. name,
  765. color: item.ChartColor,
  766. lineWidth: (chartInfo.ChartType === 6 && item.ChartStyle === 'spline') ? Number(item.ChartWidth) : 0,
  767. fillColor: (chartInfo.ChartType === 3 || (chartInfo.ChartType === 6 && item.ChartStyle === 'areaspline')) ? item.ChartColor : undefined,
  768. zIndex: (chartInfo.ChartType === 6 && item.ChartStyle === 'spline') ? 1 : 0, //防止组合图曲线被遮住
  769. borderWidth: 1,
  770. borderColor: item.ChartColor,
  771. ...predict_params
  772. };
  773. item.DataList = item.DataList || []
  774. for (let i of item.DataList) {
  775. obj.data.push([i.DataTimestamp, i.Value]);
  776. }
  777. if(item.DataList.length){
  778. minTimeArr.push(item.DataList[0].DataTimestamp)
  779. maxTimeArr.push(item.DataList[item.DataList.length-1].DataTimestamp)
  780. }
  781. data.push(obj);
  782. ydata.push(yItem);
  783. })
  784. // 范围为1年内 x轴显示为月/日 否则默认年/月
  785. let xAxis:any = {};
  786. const bool_time:boolean = xTimeDiffer();
  787. let minTime: number=Math.min(...minTimeArr);
  788. let maxTime=Math.max(...maxTimeArr);
  789. let step = setXaxisStep(maxTime-minTime);
  790. xAxis = bool_time ? {
  791. ...defaultOpts.xAxis,
  792. tickInterval: screen.value === 'phone' ? step : undefined,
  793. labels: {
  794. formatter: function (ctx: any) {
  795. return Highcharts.dateFormat('%m/%d', ctx.value);
  796. },
  797. style: {
  798. fontSize: '10px',
  799. },
  800. }
  801. } : {
  802. ...defaultOpts.xAxis,
  803. tickInterval: screen.value === 'phone' ? step : undefined,
  804. labels: {
  805. style: {
  806. fontSize: '10px',
  807. },
  808. },
  809. }
  810. state.options = {
  811. series: data,
  812. yAxis: ydata,
  813. xAxis
  814. };
  815. }
  816. /* 季节图 */
  817. const setSeasonOptions = () => {
  818. const chartData = state.dataList[0];
  819. let seasonYdata:any[] = [],
  820. seasonData:any[] = [],
  821. chart = {
  822. spacing: [5, 8, 2, 8],
  823. };
  824. /* 公历数据处理 处理数据列 y轴 */
  825. if (state.chartInfo.Calendar === '公历')
  826. for (let j of chartData.DataList) {
  827. //预测指标配置
  828. let predict_params = chartData.EdbInfoCategoryType === 1 ? getSeasonPredictParams(j.CuttingDataTimestamp) : {};
  829. let serie_item = {
  830. data: [] as any[],
  831. type: chartData.ChartStyle,
  832. yAxis: 0,
  833. name: j.Year,
  834. ...predict_params
  835. };
  836. const data_array = _.cloneDeep(j.DataList);
  837. data_array &&
  838. data_array.forEach((item: IParams) => {
  839. serie_item.data.push([item.DataTimestamp, item.Value]);
  840. });
  841. const index = chartData.DataList.findIndex(
  842. (item: ISeasonDataItemProps) => item.Year === j.Year
  843. );
  844. let textEn = chartData.Unit?chartData.UnitEn:''
  845. const s_yItem = {
  846. labels: {
  847. formatter: function (ctx: any) {
  848. let val = ctx.value;
  849. return index !== 0 ? '' : val;
  850. },
  851. align: 'center',
  852. style: {
  853. fontSize: '10px',
  854. },
  855. x: -5,
  856. },
  857. title: {
  858. text:language.value=='ch'?`${chartData.Unit}`:textEn,
  859. // text: null,
  860. align: 'high',
  861. rotation: 0,
  862. y: -15,
  863. offset: -(10 * chartData.Unit.length),
  864. },
  865. max: Number(chartData.MaxData),
  866. min: Number(chartData.MinData),
  867. ...defaultOpts.yAxis,
  868. };
  869. seasonData.push(serie_item);
  870. seasonYdata.push(s_yItem);
  871. }
  872. /* 农历数据处理 */
  873. let filterArr =
  874. state.chartInfo.Calendar === '农历'
  875. ? chartData.DataList.List.filter(
  876. (item: ILunarItem, index: number) => index > 0
  877. )
  878. : [];
  879. if (state.chartInfo.Calendar === '农历')
  880. for (let j of filterArr) {
  881. //预测指标配置
  882. let predict_params = chartData.EdbInfoCategoryType === 1 ? getSeasonPredictParams(j.CuttingDataTimestamp) : {};
  883. let serie_item = {
  884. data: [] as any[],
  885. type: chartData.ChartStyle,
  886. yAxis: 0,
  887. name: j.Year,
  888. ...predict_params
  889. };
  890. const data_array = _.cloneDeep(j.Items);
  891. data_array &&
  892. data_array.forEach((item: IParams) => {
  893. serie_item.data.push([item.DataTimestamp, item.Value]);
  894. });
  895. const index = filterArr.findIndex(
  896. (item: ILunarItem) => item.Year === j.Year
  897. );
  898. let textEn = chartData.Unit?chartData.UnitEn:''
  899. const s_yItem = {
  900. labels: {
  901. formatter: function (ctx: any) {
  902. let val = ctx.value;
  903. return index !== 0 ? '' : val;
  904. },
  905. align: 'center',
  906. style: {
  907. fontSize: '10px',
  908. },
  909. x: -5,
  910. },
  911. title: {
  912. text:language.value=='ch'?`${chartData.Unit}`:textEn,
  913. // text: null,
  914. align: 'high',
  915. rotation: 0,
  916. y: -15,
  917. offset: -(10 * chartData.Unit.length),
  918. },
  919. max: Number(chartData.MaxData),
  920. min: Number(chartData.MinData),
  921. ...defaultOpts.yAxis,
  922. };
  923. seasonData.push(serie_item);
  924. seasonYdata.push(s_yItem);
  925. }
  926. // 季节图x轴显示月/日 周度指标额外处理时间轴显示
  927. const xAxis = {
  928. ...defaultOpts.xAxis,
  929. tickInterval: screen.value === 'phone' ? 24 * 3600 * 1000 * 60 : undefined,
  930. labels: {
  931. formatter: function (ctx: any) {
  932. return Highcharts.dateFormat('%m/%d', ctx.value);
  933. },
  934. style: {
  935. fontSize: '10px',
  936. },
  937. },
  938. };
  939. // 季节图提示框显示 月/日
  940. defaultOpts.tooltip = {
  941. split: false,
  942. shared: true,
  943. dateTimeLabelFormats: {
  944. // 时间格式化字符
  945. day: '%m/%d',
  946. week: '%m/%d',
  947. month: '%m/%d',
  948. year: '%m/%d',
  949. },
  950. xDateFormat: '%m/%d',
  951. // valueDecimals: 2,
  952. };
  953. //农历默认选中一年数据并隐藏按钮 公历显示全部数据
  954. let rangeSelector = state.chartInfo.Calendar === '农历'
  955. ? {
  956. enabled: true,
  957. selected: 0,
  958. inputStyle: {
  959. display: 'none',
  960. },
  961. labelStyle: {
  962. display: 'none',
  963. },
  964. buttonTheme: {
  965. style: {
  966. display: 'none',
  967. },
  968. },
  969. buttons: [
  970. {
  971. type: 'month',
  972. count: 12,
  973. text: '12月',
  974. },
  975. {
  976. type: 'month',
  977. count: 15,
  978. text: '15月',
  979. },
  980. {
  981. type: 'all',
  982. text: '全部',
  983. },
  984. ],
  985. }
  986. : {
  987. enabled: false,
  988. };
  989. state.options = {
  990. colors:
  991. state.chartInfo.Calendar === '公历'
  992. ? seasonOptions.colors.slice(-chartData.DataList.length)
  993. : seasonOptions.colors.slice(-filterArr.length),
  994. series: seasonData,
  995. yAxis: seasonYdata,
  996. xAxis,
  997. rangeSelector,
  998. chart
  999. };
  1000. }
  1001. /* 散点图 第一个指标值为x轴 第二个指标为y轴*/
  1002. const setScatterChartOptions = () => {
  1003. const { dataList,chartInfo } = state;
  1004. // 取2个指标中日期相同的数据
  1005. const real_data: any[] = [];
  1006. let tmpData_date: any = {};//用来取点对应的日期
  1007. let data1 = _.cloneDeep(dataList)[0].DataList || [];
  1008. let data2 = _.cloneDeep(dataList)[1].DataList || [];
  1009. data1.forEach((_item: IParams) => {
  1010. data2.forEach((_item2: IParams) => {
  1011. if(_item.DataTimestamp === _item2.DataTimestamp) {
  1012. //日期
  1013. let itemIndex =_item.Value + "_" +_item2.Value
  1014. if(tmpData_date[itemIndex]) {
  1015. tmpData_date[itemIndex].push( moment(_item.DataTimestamp).format('YYYY/MM/DD'))
  1016. } else {
  1017. tmpData_date[itemIndex] = [moment(_item.DataTimestamp).format('YYYY/MM/DD')]
  1018. }
  1019. //值
  1020. real_data.push({
  1021. x: _item.Value,
  1022. y: _item2.Value
  1023. })
  1024. }
  1025. })
  1026. })
  1027. real_data.sort((x,y) => x-y);
  1028. //悬浮窗 拼接日期 原始指标名称
  1029. let tooltip = {
  1030. formatter: function() {
  1031. const that: any = this;
  1032. return language.value=='ch'?
  1033. `<strong>${ tmpData_date[that.x+'_'+that.y].length > 4 ? tmpData_date[that.x+'_'+that.y].slice(0,4).join()+'...' : tmpData_date[that.x+'_'+that.y].join() }</strong><br>
  1034. ${dataList[0].EdbName}: <span style="font-weight: 600"> ${that.x}</span><br>
  1035. ${dataList[1].EdbName}: <span style="font-weight: 600"> ${that.y}</span>
  1036. `:
  1037. `<strong>${ tmpData_date[that.x+'_'+that.y].length > 4 ? tmpData_date[that.x+'_'+that.y].slice(0,4).join()+'...' : tmpData_date[that.x+'_'+that.y].join() }</strong><br>
  1038. ${dataList[0].EdbNameEn}: <span style="font-weight: 600"> ${that.x}</span><br>
  1039. ${dataList[1].EdbNameEn}: <span style="font-weight: 600"> ${that.y}</span>
  1040. `
  1041. }
  1042. }
  1043. const { IsOrder,ChartColor } = dataList[0];
  1044. //y轴
  1045. let yAxis = {
  1046. title: {
  1047. text: language.value=='ch'?`${dataList[1].Unit}`:dataList[1].Unit?dataList[1].UnitEn:'',
  1048. // text: null,
  1049. align: 'high',
  1050. rotation: 0,
  1051. y: -5,
  1052. offset: -(10 * dataList[1].Unit.length),
  1053. },
  1054. labels: {
  1055. formatter: function (ctx: any) {
  1056. return ctx.value;
  1057. },
  1058. align: 'center',
  1059. },
  1060. opposite: false,
  1061. reversed: IsOrder,
  1062. min: Number(dataList[0].MinData),
  1063. max: Number(dataList[0].MaxData),
  1064. tickWidth: 1,
  1065. tickLength: 5,
  1066. lineWidth: 1,
  1067. lineColor: '#bfbfbf',
  1068. tickColor: '#bfbfbf',
  1069. offset: 0,
  1070. visible: true,
  1071. gridLineWidth: 0,
  1072. tickPosition: 'inside',
  1073. endOnTick: false,
  1074. startOnTick: false,
  1075. showLastLabel: true,
  1076. tickPixelInterval: 50
  1077. }
  1078. //数据列
  1079. let series: any = {
  1080. data: [],
  1081. type: 'scatter',
  1082. name: language.value == 'ch'?`${chartInfo.ChartName}${IsOrder ? '(逆序)' : ''}`:`${chartInfo.ChartNameEn}${IsOrder ? '(reserve)' : ''}`,
  1083. color: ChartColor,
  1084. lineWidth: 0
  1085. }
  1086. real_data.forEach(_ => {
  1087. series.data.push([_.x,_.y])
  1088. })
  1089. state.options = {
  1090. title: {
  1091. text:''
  1092. },
  1093. series: [ series ],
  1094. yAxis,
  1095. xAxis: {
  1096. ...scatterXAxis,
  1097. title: {
  1098. text: language.value=='ch'?`${dataList[0].Unit}`:dataList[0].Unit?dataList[0].UnitEn:'',
  1099. // text: null,
  1100. align: 'high',
  1101. rotation: 0,
  1102. x: 0,
  1103. offset: 20,
  1104. },
  1105. },
  1106. tooltip
  1107. }
  1108. console.log(state.options)
  1109. }
  1110. /* 获取图表详情后赋值柱状图数据 */
  1111. const initBarData = (data: { XEdbIdValue: number[]; YDataList: any; EdbInfoList: any; ChartInfo: any; }) => {
  1112. const { XEdbIdValue,YDataList,EdbInfoList,ChartInfo } = data;
  1113. state.barDateList = YDataList;
  1114. state.barXIdData = XEdbIdValue;
  1115. state.barEdbData = EdbInfoList;
  1116. state.chartLimit = {
  1117. min: Number(ChartInfo.LeftMin),
  1118. max: Number(ChartInfo.LeftMax),
  1119. }
  1120. setBarChart();
  1121. }
  1122. /* 奇怪柱状图 和以上逻辑无公用点 依赖数据为单独的数据
  1123. x轴为指标名称的柱形图 以日期作为series
  1124. */
  1125. const setBarChart = () => {
  1126. const {barDateList,barXIdData,chartLimit,barEdbData,chartInfo} = state;
  1127. let seriesData: { data: any; type: string; yAxis: number; name: any; color: any; chartType: string; }[] = [];
  1128. const data = _.cloneDeep(barDateList);
  1129. let categories = language.value==='ch'
  1130. ? barXIdData.map((_:number) => barEdbData.find((edb: { EdbInfoId: number; }) => edb.EdbInfoId===_).EdbAliasName)
  1131. : barXIdData.map((_:number) => barEdbData.find((edb: { EdbInfoId: number; }) => edb.EdbInfoId===_).EdbNameEn)
  1132. //x轴
  1133. let xAxis = {
  1134. ...scatterXAxis,
  1135. categories,
  1136. tickWidth: 1,
  1137. title: {
  1138. text: ``,
  1139. align: 'high',
  1140. rotation: 0,
  1141. x: 0,
  1142. offset: 20,
  1143. },
  1144. }
  1145. const { max,min } = chartLimit;
  1146. console.log(max,min)
  1147. //y轴
  1148. let yAxis = {
  1149. ...basicYAxis,
  1150. title: {
  1151. text: language.value==='ch' ? chartInfo.Unit : chartInfo.UnitEn,
  1152. align: 'high',
  1153. rotation: 0,
  1154. y: -15,
  1155. offset: 0,
  1156. },
  1157. labels: {
  1158. formatter: function (ctx:any) {
  1159. let val = ctx.value;
  1160. return val;
  1161. },
  1162. align: 'center',
  1163. },
  1164. min: Number(min),
  1165. max: Number(max),
  1166. opposite: false,
  1167. tickWidth: 1,
  1168. }
  1169. //数据列
  1170. data.forEach((item: { Value: number; Name: string; Date: string; Color: string; }) => {
  1171. let serie_item = {
  1172. data: item.Value,
  1173. type: 'column',
  1174. yAxis: 0,
  1175. name: language.value==='ch' ? (item.Name || item.Date) : item.Date,
  1176. color: item.Color,
  1177. chartType: 'linear'
  1178. };
  1179. seriesData.push(serie_item)
  1180. })
  1181. state.options = {
  1182. title: {
  1183. text:''
  1184. },
  1185. plotOptions: {
  1186. column:{
  1187. stacking: null,
  1188. },
  1189. },
  1190. series: seriesData,
  1191. yAxis: [ yAxis ],
  1192. xAxis
  1193. }
  1194. }
  1195. /* 商品价格曲线获取详情赋值 */
  1196. const initCommodityData = (data: { XDataList: any[]; YDataList: any; EdbInfoList: any; ChartInfo: any; DataResp?:any }) => {
  1197. const { XDataList,YDataList,EdbInfoList,ChartInfo,DataResp } = data;
  1198. state.commodityEdbList = EdbInfoList;
  1199. state.commodityChartData = ChartInfo.Source===5?DataResp.YDataList:YDataList;
  1200. state.commodityXData = ChartInfo.Source===5?DataResp.XDataList:XDataList;
  1201. if(ChartInfo.Source===5) {
  1202. state.chartInfo = {
  1203. ...state.chartInfo,
  1204. ProfitName: DataResp.ProfitName,
  1205. ProfitNameEn: DataResp.ProfitNameEn
  1206. }
  1207. }
  1208. state.chartLimit = {
  1209. min: Number(ChartInfo.LeftMin),
  1210. max: Number(ChartInfo.LeftMax)
  1211. }
  1212. setCommodityChart();
  1213. }
  1214. /* 商品价格曲线设置 绘图逻辑同奇怪柱形图*/
  1215. const setCommodityChart = () => {
  1216. const {chartLimit,commodityChartData,commodityXData,commodityEdbList,chartInfo} = state;
  1217. let seriesData:any[] = [];
  1218. const data = _.cloneDeep(commodityChartData);
  1219. //x轴
  1220. let xAxis = {
  1221. ...scatterXAxis,
  1222. categories: commodityXData.map(_ => language.value === 'ch' ? _.Name:_.NameEn),
  1223. tickWidth: 1,
  1224. title: {
  1225. text: ``,
  1226. align: 'high',
  1227. rotation: 0,
  1228. x: 0,
  1229. offset: 20,
  1230. },
  1231. }
  1232. const { max,min } = chartLimit;
  1233. //y轴
  1234. let yAxis = {
  1235. ...basicYAxis,
  1236. title: {
  1237. text: language.value === 'ch' ? commodityEdbList[0].Unit : commodityEdbList[0].UnitEn,
  1238. align: 'high',
  1239. rotation: 0,
  1240. y: -15,
  1241. offset: 0,
  1242. },
  1243. labels: {
  1244. formatter: function (ctx:any) {
  1245. let val = ctx.value;
  1246. return val;
  1247. },
  1248. align: 'center',
  1249. },
  1250. min: Number(min),
  1251. max: Number(max),
  1252. opposite: false,
  1253. tickWidth: 1,
  1254. }
  1255. //数据列
  1256. data.forEach((item: { Value: number[]; Name: string; Date: string; Color: string;NameEn: string,XEdbInfoIdList: number[],NoDataEdbList: number[] }) => {
  1257. //处理首或/尾全是无效数据的以null填充
  1258. let filterData = filterInvalidData(item)
  1259. let serie_item = {
  1260. data: filterData,
  1261. type: 'spline',
  1262. yAxis: 0,
  1263. name: language.value === 'ch' ? item.Name : item.NameEn,
  1264. color: item.Color,
  1265. chartType: 'linear',
  1266. lineWidth: 3,
  1267. marker: {
  1268. enabled: false
  1269. }
  1270. };
  1271. seriesData.push(serie_item)
  1272. })
  1273. //tooltip
  1274. let tooltip = {
  1275. formatter: function() {
  1276. const ctx: any = this;
  1277. let str: string = '';
  1278. if(language.value === 'ch') {
  1279. ctx.points.forEach((item: { series:{name: string},y: number,color: string }) => {
  1280. let obj_item = data.find((_:any) => _.Name === item.series.name);
  1281. let index = commodityXData.findIndex(_ => _.Name === ctx.x);
  1282. //合约显示
  1283. let haveContract = obj_item.XEdbInfoIdList[index];
  1284. if(haveContract) {
  1285. // 利润曲线指标名
  1286. let edb_name = chartInfo.Source === 5
  1287. ? (index === 0 ? obj_item.NameList[index] : `${chartInfo.ProfitName}(${obj_item.NameList[index]})`)
  1288. : commodityEdbList.find(_ => _.EdbInfoId === obj_item.XEdbInfoIdList[index]).EdbName;
  1289. str+=`<b>${ edb_name }</b>`
  1290. if(!obj_item.NoDataEdbList.includes(obj_item.XEdbInfoIdList[index])) {
  1291. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: ${item.y}<br>`
  1292. }else {
  1293. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: 无<br>`
  1294. }
  1295. }
  1296. })
  1297. }else {
  1298. ctx.points.forEach((item: { series:{name: string},y: number,color: string }) => {
  1299. let obj_item = data.find((_: any) => _.NameEn === item.series.name);
  1300. let index = commodityXData.findIndex(_ => _.NameEn === ctx.x);
  1301. let haveContract = obj_item.XEdbInfoIdList[index];
  1302. if(haveContract) {
  1303. let edb_name = chartInfo.Source === 5
  1304. ? (index === 0 ? obj_item.NameList[index] : `${chartInfo.ProfitNameEn}(${obj_item.NameList[index]})`)
  1305. : commodityEdbList.find(_ => _.EdbInfoId === obj_item.XEdbInfoIdList[index]).EdbNameEn;
  1306. str+=`<b>${ edb_name }</b>`
  1307. if(!obj_item.NoDataEdbList.includes(obj_item.XEdbInfoIdList[index])) {
  1308. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: ${item.y}<br>`
  1309. }else {
  1310. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: 无<br>`
  1311. }
  1312. }
  1313. })
  1314. }
  1315. return str || '无合约'
  1316. },
  1317. shared: true
  1318. }
  1319. state.options = {
  1320. title: {
  1321. text:''
  1322. },
  1323. series: seriesData,
  1324. yAxis: [ yAxis ],
  1325. xAxis,
  1326. tooltip
  1327. }
  1328. };
  1329. /* 处理无效数据为null */
  1330. const filterInvalidData = (item:{ Value: number[]; Name: string; Date: string; Color: string;NameEn: string,XEdbInfoIdList: number[],NoDataEdbList: number[] })=> {
  1331. let validateArr = item.XEdbInfoIdList.filter(_ => _&&!item.NoDataEdbList.includes(_));
  1332. let first_index = item.XEdbInfoIdList.findIndex(_ => _ === validateArr[0]);
  1333. let last_index = item.XEdbInfoIdList.findIndex(_ => _ === validateArr[validateArr.length-1]);
  1334. console.log('first_index',first_index)
  1335. console.log('last_index',last_index)
  1336. let arr = item.Value.map((item,index:number) => {
  1337. if(index < first_index || index > last_index) {
  1338. return null
  1339. }else {
  1340. return item
  1341. }
  1342. })
  1343. return arr;
  1344. }
  1345. /* 设置options */
  1346. const setOptions = () => {
  1347. // ChartType: 1曲线图 2季节图 3面积图 4柱状图 5散点图 6组合图 季节图中公历和农历数据结构不同
  1348. const { chartInfo } = state;
  1349. const chartSetMap: any = {
  1350. 1: setDefaultLineOptions,
  1351. 2: setSeasonOptions,
  1352. 3: setStackOrCombinChart,
  1353. 4: setStackOrCombinChart,
  1354. 5: setScatterChartOptions,
  1355. 6: setStackOrCombinChart
  1356. };
  1357. chartSetMap[chartInfo.ChartType]()
  1358. };
  1359. /* 拼接动态的指标名称小标签 */
  1360. const concatDynamicTag = ({ IsAxis,IsOrder,EdbInfoType,LeadValue,LeadUnit }: IDataProps,lang:String='ch'): string => {
  1361. // IsAxis左轴1 右轴0 2右2轴
  1362. //IsOrder正序false 逆序true
  1363. //EdbInfoType是否是领先指标
  1364. const axisLabelMap:any = lang=='ch'?{
  1365. 0: '右轴',
  1366. 2: '右2轴'
  1367. }:{
  1368. 0: 'RHS',
  1369. 2: '2-RHS'
  1370. }
  1371. const orderLabelMap:any = lang=='ch'?{
  1372. 1: '逆序'
  1373. }:{
  1374. 1: 'REV'
  1375. }
  1376. const edbInfoMap:any = lang=='ch'?{
  1377. 0: '领先'
  1378. }:{
  1379. 0: 'Lead'
  1380. }
  1381. const leadUnitEnMap:any = {
  1382. '年': 'Y',
  1383. '季': 'Q',
  1384. '月': 'M',
  1385. '周': 'W',
  1386. '天': 'D',
  1387. }
  1388. //英文领先单位转换
  1389. const edbLeadUnit = lang=='ch' ? LeadUnit : leadUnitEnMap[LeadUnit];
  1390. let axis_tag = axisLabelMap[IsAxis] || '';
  1391. //逆序拼接
  1392. let order_tag = orderLabelMap[Number(IsOrder)] ? `${axis_tag ? ',': ''}${orderLabelMap[Number(IsOrder)]}` : ''
  1393. //领先拼接
  1394. let edb_tag = edbInfoMap[EdbInfoType] ? `${(axis_tag||order_tag) ? ',' : '' }${edbInfoMap[EdbInfoType]} ${LeadValue}${edbLeadUnit}` : '';
  1395. return (axis_tag || order_tag || edb_tag) ? `(${axis_tag}${order_tag}${edb_tag})` : ''
  1396. }
  1397. /* 预测配置 分区 */
  1398. const getPredictParams = ({LatestDate,MoveLatestDate,PredictChartColor,ChartStyle}: IDataProps,chartStyle='') => {
  1399. return {
  1400. zoneAxis: 'x',
  1401. zones: [{
  1402. value: new Date(MoveLatestDate||LatestDate).getTime()+1
  1403. }, {
  1404. dashStyle: 'ShortDot',
  1405. color:(ChartStyle==='column' || chartStyle==='column') ? 'transparent' : PredictChartColor
  1406. }]
  1407. }
  1408. }
  1409. /* 季节图预测数据 年份=分割点年份做分割 年份>分割点年份全为预测 */
  1410. const getSeasonPredictParams = (timestamp: number) => {
  1411. return timestamp
  1412. ? {
  1413. zoneAxis: 'x',
  1414. zones: [{
  1415. value: new Date(timestamp).getTime()+1
  1416. }, {
  1417. dashStyle: 'ShortDot',
  1418. }]
  1419. }
  1420. : {}
  1421. }
  1422. /* 复制标题 */
  1423. const copyText = () => {
  1424. const { chartInfo } = state;
  1425. let input = document.createElement("input");
  1426. input.value = chartInfo.ChartName;
  1427. document.body.appendChild(input)
  1428. input.select();
  1429. document.execCommand('copy');
  1430. document.body.removeChild(input);
  1431. ElMessage.success('复制标题成功')
  1432. }
  1433. /* 分享链接 */
  1434. const copyUrl = () => {
  1435. let input = document.createElement("input");
  1436. input.value = location.href;
  1437. document.body.appendChild(input)
  1438. input.select();
  1439. document.execCommand('copy');
  1440. document.body.removeChild(input);
  1441. ElMessage.success('复制链接成功')
  1442. }
  1443. const refreshChart = _.debounce(async () => {
  1444. loading.value = true;
  1445. let res: any=null
  1446. if([1,6,7,8,9].includes(state.chartInfo.Source)){
  1447. res=await ChartApi.refreshChart({UniqueCode: state.chartInfo.UniqueCode})
  1448. }else if([2,5].includes(state.chartInfo.Source)){
  1449. res=await ChartApi.refreshCommordityChart({UniqueCode: state.chartInfo.UniqueCode});
  1450. }else if([3,4].includes(state.chartInfo.Source)){
  1451. res=await ChartApi.refreshRelevanceChart({UniqueCode: state.chartInfo.UniqueCode});
  1452. }
  1453. loading.value = false;
  1454. res.Ret === 200 && getChartInfo('refresh');
  1455. },400)
  1456. return {
  1457. ...toRefs(state),
  1458. loading,
  1459. haveData,
  1460. getChartInfo,
  1461. openNew,
  1462. copyUrl,
  1463. isShare,
  1464. language,
  1465. refreshChart,
  1466. copyText
  1467. };
  1468. },
  1469. });
  1470. </script>
  1471. <style scoped lang="less">
  1472. @import './index.less';
  1473. </style>