chartPublic.js 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307
  1. import {
  2. defaultOpts,
  3. seasonOptions,
  4. yearSelector,
  5. } from '@/utils/defaultOptions';
  6. import Highcharts from 'highcharts';
  7. import { dataBaseInterface } from '@/api/api';
  8. import * as preDictEdbInterface from '@/api/modules/predictEdbApi.js';
  9. import futuresInterface from '@/api/modules/futuresBaseApi';
  10. import chartRelevanceApi from '@/api/modules/chartRelevanceApi';
  11. import { fittingEquationInterface,statisticFeatureInterface,crossVarietyInterface } from '@/api/modules/chartRelevanceApi';
  12. //获取RGBA的透明度
  13. const parseRgbaColor = (color='rgba(51, 51, 51, 1)') => {
  14. const arr = color.match(/(\d(\.\d+)?)+/g) || ['','','',1];
  15. return parseFloat(arr[3]||1)
  16. }
  17. /* 散点x轴 */
  18. const scatterXAxis = {
  19. tickPosition: 'inside',
  20. lineColor: '#bfbfbf',
  21. tickColor: '#bfbfbf',
  22. tickLength:5,
  23. ordinal: false,
  24. type: 'linear'
  25. }
  26. /* 曲线基础y轴静态配置 */
  27. const basicYAxis = {
  28. tickLength: 5,
  29. lineWidth: 1,
  30. lineColor: '#bfbfbf',
  31. tickColor: '#bfbfbf',
  32. // offset: 0,
  33. visible: true,
  34. gridLineWidth: 0,
  35. tickPosition: 'inside',
  36. endOnTick: false,
  37. startOnTick: false,
  38. showLastLabel: true,
  39. tickPixelInterval: 50,
  40. }
  41. /**备注一下 越多越乱
  42. * @params
  43. * Source 1 ; chartType 1曲线 2季节 3面积 4堆积柱 5散点 6组合 7柱形 10截面散点 11雷达图
  44. * 2 商品价格
  45. * 3 相关性
  46. * 4 滚动相关性
  47. * 5 商品利润
  48. * 6 拟合方程
  49. * 7 统计特征/标准差
  50. * 8 统计特征/百分位
  51. * 9 统计特征/频率
  52. * 10 跨品种分析
  53. */
  54. export const chartSetMixin = {
  55. data() {
  56. return {
  57. /**
  58. * 默认区间15年至今 值等于 5、6、20 是自定义时间段
  59. * 20代表最近几年 季节性图默认 最近5年
  60. * 6代表至今 只需要选择开始日期
  61. * 5代表范围 需要选择开始日期和结束日期
  62. */
  63. year_select: yearSelector[0].value,
  64. sameOptionType:[1,3,4,5,6],// 头部一样 配置一样的图表类型 曲线 散点 柱状 面积 组合
  65. // yearSelector, //年份按钮组
  66. select_date: '', //自定义时间段
  67. count_year: 0, //最近年数
  68. isDateDia: false, // 时间段弹窗
  69. earliestDate:'', // 最早的日期 - 起始日期
  70. latestDate:'', //最晚日期 - 最新日期
  71. dateForm: {},
  72. dateTip: /* '请选择时间段' */ this.$t('Chart.choose_time'),
  73. predefineColors: defaultOpts.colors.slice(0, 2), //定义颜色蓝,红 默认颜色
  74. fre_options: ['年', '季', '月', '周', '天'], //领先指标频度配置
  75. //领先频度对应英文
  76. leadUnitEnMap: {
  77. '年': 'Y',
  78. '季': 'Q',
  79. '月': 'M',
  80. '周': 'W',
  81. '天': 'D',
  82. },
  83. tableData: [],//表格指标数据
  84. options: {}, //配置options
  85. leftIndex: -1, //左侧上下限对应下标
  86. rightIndex: -1, //右侧上下限对应下标
  87. rightTwoIndex: -1,//右2上下限对应下标
  88. left_extreme: [],
  89. right_extreme: [],
  90. chartItemStyleArr:[
  91. { label: '曲线图', key: 1 ,value: 'spline'},
  92. { label: '折线图', key: 2 ,value: 'line'},
  93. // { label: '堆积面积图', key: 3 ,value: 'areaspline'},
  94. { label: '堆积柱状图', key: 4 ,value: 'column'},
  95. ],//组合图可选样式
  96. isSetExtremeValue: false,//控制添加散点图时是否重置上下限
  97. isShowSaveOther: false,//图表另存为弹窗
  98. // -------------切换图表中英文
  99. // currentLang:'zh', // ch(中文) en(英文)
  100. setEnName:false,
  101. // 传入的formItem所需内容
  102. formItemArray:[],
  103. /* 奇怪柱形图 */
  104. barDateList: [],//柱形图的绘图数据
  105. barXData: [],//柱形图的x轴
  106. barXIdList: [],//x轴id数组 用于切换英文遍历用
  107. barEdbData: [],//柱形图的表格数据 只用于取值
  108. chartLimit: {
  109. min:'', //左轴上下限
  110. max:'',
  111. rightMin:'',//右轴上下限
  112. rightMax:'',
  113. rightTwoMin:'',//右二轴上下限
  114. rightTwoMax:'',
  115. },
  116. /* 商品价格曲线 本来逻辑分开写 但需求又得加入myeta和eta图库共存 还是写一块算了 */
  117. commodityChartData: [],
  118. commodityXData: [],
  119. commodityEdbList: [],
  120. /* 时间截面散点图 */
  121. sectionScatterData: {},
  122. /* 相关性图表 */
  123. relevanceChartData:null,
  124. relevanceUnitEnMap:{
  125. '年': 'Year',
  126. '季': 'Season',
  127. '月': 'Month',
  128. '周': 'Week',
  129. '天': 'Day',
  130. },
  131. /* 统计频率图 */
  132. statisticFrequencyData: {},
  133. // 季节性图和额外配置 这里为了预览
  134. SeasonExtraConfig:{
  135. ChartLegend:[], // 图例名称数组
  136. XStartDate:"01-01", // 横坐标显示范围 - 开始
  137. XEndDate:"12-31", // 横坐标显示范围-结束
  138. JumpYear:0, //是否跨年
  139. },
  140. /* 跨品种分析图 */
  141. crossVarietyChartData: {},
  142. /* 雷达图 */
  143. radarChartData: {},
  144. // 区间分析图数据
  145. intervalAnalysisChartData:{},
  146. /* 修改对应版本信息弹窗 替换原有设置英文*/
  147. isLangInfoDia: false,
  148. sectionalCombinationData:{},//截面组合图数据
  149. IsHeap:false,//是否堆积
  150. }
  151. },
  152. computed:{
  153. tableColums(){
  154. return [
  155. {
  156. label: this.$t('Edb.Detail.e_name'),
  157. key: 'EdbName',
  158. enKey:'EdbNameEn',
  159. inputTip:'点击输入英文指标名称',
  160. minwidthsty: '150px',
  161. },
  162. {
  163. label: this.$t('Edb.Detail.e_id'),
  164. key: 'EdbCode',
  165. widthsty: '120px',
  166. },
  167. {
  168. label: this.$t('Edb.Detail.e_fre'),
  169. key: 'Frequency',
  170. enKey:'FrequencyEn',
  171. minwidthsty: '60px',
  172. },
  173. {
  174. label: this.$t('Edb.Detail.e_unit'),
  175. key: 'Unit',
  176. enKey:'UnitEn',
  177. inputTip:'英文单位',
  178. minwidthsty: '50px',
  179. },
  180. {
  181. label: this.$t('Edb.Detail.e_start_time'),
  182. key: 'StartDate',
  183. minwidthsty: '100px',
  184. },
  185. {
  186. label: this.$t('Edb.Detail.e_latest_date'),
  187. key: 'LatestDate',
  188. minwidthsty: '90px',
  189. },
  190. {
  191. label: this.$t('Edb.Detail.e_latest_value'),
  192. key: 'LatestValue',
  193. minwidthsty: '90px',
  194. },
  195. {
  196. label: this.$t('Edb.Detail.e_recent_time'),
  197. key: 'ModifyTime',
  198. minwidthsty: '100px',
  199. },
  200. {
  201. label: this.$t('Edb.Detail.source'),
  202. key: 'SourceName',
  203. },
  204. ]
  205. },
  206. yearSelector() {
  207. return yearSelector
  208. },
  209. currentLang() {
  210. return this.$store.state.lang
  211. }
  212. },
  213. watch: {
  214. /* 奇怪柱状图数据 */
  215. barDateList: {
  216. handler(newval) {
  217. console.log('bar')
  218. newval.length && this.barXData.length && this.setBarChart();
  219. },
  220. deep: true
  221. },
  222. sectionScatterData: {
  223. handler(newval) {
  224. newval.DataList && this.setSectionScatterChart();
  225. },
  226. deep: true
  227. },
  228. // 截面组合图
  229. sectionalCombinationData: {
  230. handler(newval) {
  231. newval.SeriesList && this.setSectionalCombinationChart();
  232. },
  233. deep: true
  234. },
  235. currentLang() {
  236. this.changeLanguage()
  237. }
  238. },
  239. methods: {
  240. /* --------------------------------------------切换中英文 */
  241. async changeLanguage(){
  242. this.search_txt = '';
  243. if(!this.$refs.chartRef) return
  244. //不同图表来源 1eta图 2商品价格图 3相关性图表
  245. const sourceMap = {
  246. 1: this.changeOptions,
  247. 2: this.changeCommodityLang,
  248. 3: this.changeRelevanceLang,
  249. 4: this.changeRelevanceLang,
  250. 5: this.changeCommodityLang
  251. }
  252. sourceMap[this.chartInfo.Source]&&sourceMap[this.chartInfo.Source]()
  253. },
  254. /* 打开编辑信息弹窗 */
  255. async openLangInfoDia() {
  256. this.formItemArray={}
  257. this.formItemArray.chartInfo=[]
  258. this.formItemArray.chartsList=[]
  259. this.formItemArray.xData=[]
  260. this.formItemArray.chartInfo.push({
  261. label:/* '图表名称' */this.$t('Chart.Detail.chart_name'),
  262. value: this.currentLang==='en'?this.chartInfo.ChartNameEn:this.chartInfo.ChartName,
  263. key:'ChartName',
  264. id:this.chartInfo.ChartInfoId,
  265. source: this.chartInfo.Source,
  266. placeholder:/* '请输入图表名称' */this.$t('Chart.InputHolderAll.input_common',{label:this.$t('Chart.Detail.chart_name')})
  267. })
  268. if([1,2,5,11].includes(this.chartInfo.Source)){ //需要设置指标的
  269. this.tableData.map(item =>{
  270. this.formItemArray.chartsList.push([
  271. {
  272. label:/* '指标名称' */this.$t('Edb.Detail.e_name'),
  273. value:this.currentLang==='en'?item.EdbNameEn:item.EdbName,
  274. key:'EdbName',
  275. id:item.EdbInfoId,
  276. placeholder:/* '请输入指标名称' */ this.$t('Edb.InputHolderAll.input_common',{label: this.$t('Edb.Detail.e_name')})
  277. },
  278. {
  279. label:/* '单位' */this.$t('Edb.Detail.e_unit'),
  280. value:this.currentLang==='en'?item.UnitEn:item.Unit,
  281. key:'Unit',
  282. id:item.EdbInfoId,
  283. placeholder:/* '请输入单位' */ this.$t('Edb.InputHolderAll.input_common',{label: this.$t('Edb.Detail.e_unit')})
  284. }
  285. ])
  286. })
  287. }
  288. // 商品价格曲线增加编辑X轴
  289. if([2,5].includes(this.chartInfo.Source)){
  290. const arr=this.commodityXData||[]
  291. console.log(arr);
  292. this.formItemArray.xData=arr.map(item=>{
  293. return {
  294. name:this.currentLang==='en'?item.NameEn:item.Name,
  295. }
  296. })
  297. }
  298. //价格曲线
  299. if(this.chartInfo.Source===2) {
  300. this.formItemArray.chartInfo.push({
  301. label:/* '期货名称' */this.$t('Chart.Detail.good_name'),
  302. value:this.currentLang==='en'?this.commodityEdbList[1].EdbNameEn:this.commodityEdbList[1].EdbName,
  303. key:'FutureGoodName',
  304. id:this.chartInfo.ChartInfoId,
  305. placeholder:/* '请输入期货名称' */this.$t('Chart.InputHolderAll.input_common',{label:this.$t('Chart.Detail.good_name')})
  306. })
  307. }
  308. //利润曲线
  309. else if(this.chartInfo.Source===5) {
  310. this.formItemArray.chartInfo.push({
  311. label:/* '盘面利润名称' */this.$t('Chart.Detail.profit_name'),
  312. value: this.currentLang==='en'?this.chartInfo.ProfitNameEn:this.chartInfo.ProfitName,
  313. key:'ProfitName',
  314. id:this.chartInfo.ChartInfoId,
  315. placeholder:/* '请输入盘面利润名称' */this.$t('Chart.InputHolderAll.input_common',{label:this.$t('Chart.Detail.profit_en_name')})
  316. })
  317. }
  318. //跨品种分析
  319. else if(this.chartInfo.Source===10) {
  320. let { Data } = await crossVarietyInterface.chartLangOption({ChartInfoId: this.chartInfo.ChartInfoId})
  321. const { TagList,VarietyList } = Data;
  322. this.formItemArray.chartInfo.push({
  323. label:/* 'X轴名称' */this.$t('Chart.Detail.x_name'),
  324. value:this.currentLang==='en'?this.crossVarietyChartData.XNameEn:this.crossVarietyChartData.XName,
  325. key:'XName',
  326. id:TagList[0].ChartTagId,
  327. placeholder:/* '请输入X轴名称' */this.$t('Chart.InputHolderAll.input_common',{label:this.$t('Chart.Detail.x_name')})
  328. },
  329. {
  330. label:/* 'Y轴名称' */this.$t('Chart.Detail.y_name'),
  331. value:this.currentLang==='en'?this.crossVarietyChartData.YNameEn:this.crossVarietyChartData.YName,
  332. key:'YName',
  333. id:TagList[1].ChartTagId,
  334. placeholder:/* '请输入Y轴名称' */this.$t('Chart.InputHolderAll.input_common',{label:this.$t('Chart.Detail.y_name')})
  335. })
  336. VarietyList.forEach(item => {
  337. this.formItemArray.chartsList.push(
  338. {
  339. label:/* '品种名称' */this.$t('Chart.Detail.variety_name'),
  340. value:this.currentLang==='en'?item.ChartVarietyNameEn:item.ChartVarietyName,
  341. key:'ChartVarietyName',
  342. id:item.ChartVarietyId,
  343. placeholder:/* '请输入品种名称' */this.$t('Chart.InputHolderAll.input_common',{label:this.$t('Chart.Detail.variety_name')})
  344. }
  345. )
  346. })
  347. }
  348. this.isLangInfoDia = true
  349. },
  350. /* 更新版本图表信息 */
  351. async updateLang(paramsData) {
  352. let res=null
  353. if([2,5].includes(this.chartInfo.Source)){//商品价格
  354. const ChartEdbInfoList=paramsData.ChartEdbInfoList.map(i=>{
  355. return {
  356. EdbInfoId:i.EdbInfoId,
  357. EdbName:i.EdbName,
  358. Unit:i.Unit
  359. }
  360. })
  361. const XDataList=paramsData.xData.map(x=>x.name)
  362. res=await futuresInterface.setChartLangInfo({
  363. ChartInfoId: paramsData.ChartInfoId,
  364. ChartName: paramsData.ChartName,
  365. // Unit: paramsData.ChartEdbInfoList[0].Unit || '',
  366. // EdbName: paramsData.ChartEdbInfoList[0].EdbName || '',
  367. FutureGoodName: paramsData.FutureGoodName || '',
  368. ProfitName: paramsData.ProfitName || '',
  369. ChartEdbInfoList:ChartEdbInfoList,
  370. XDataList:XDataList
  371. })
  372. }else if(this.chartInfo.Source===3){//相关性
  373. res=await chartRelevanceApi.setChartLangInfo({
  374. ChartInfoId: paramsData.ChartInfoId,
  375. ChartName: paramsData.ChartName
  376. })
  377. }else if(this.chartInfo.Source===6){//拟合方程
  378. res=await fittingEquationInterface.setChartLangInfo({
  379. ChartInfoId: paramsData.ChartInfoId,
  380. ChartName: paramsData.ChartName
  381. })
  382. }else if([7,8,9].includes(this.chartInfo.Source)){//统计特征
  383. res=await statisticFeatureInterface.setChartLangInfo({
  384. ChartInfoId: paramsData.ChartInfoId,
  385. ChartName: paramsData.ChartName
  386. })
  387. }else if(this.chartInfo.Source === 10) {//跨品种分析
  388. res=await crossVarietyInterface.setChartLangInfo(paramsData)
  389. }else{
  390. res = await dataBaseInterface.setChartLangInfo(paramsData)
  391. }
  392. if(res.Ret !==200) return
  393. this.$message.success(this.$t('MsgPrompt.edit_msg'))
  394. this.getChartInfo()
  395. this.isLangInfoDia = false
  396. },
  397. /* 切换柱形图中英文 */
  398. changeBarOptions() {
  399. //x轴
  400. this.options.xAxis.categories = this.barXIdList.map(_ => this.currentLang === 'zh'
  401. ? this.barEdbData.find(edb => edb.EdbInfoId===_).EdbAliasName
  402. : this.barEdbData.find(edb => edb.EdbInfoId===_).EdbNameEn)
  403. // 单位
  404. this.options.yAxis.forEach(item => {
  405. item.title.text = this.currentLang === 'zh' ? this.chartInfo.Unit : this.chartInfo.Unit;
  406. });
  407. },
  408. // 切换中英文时,更改图表配置
  409. changeOptions(){
  410. // console.log(this.tableData,'tableData');
  411. // console.log(this.currentLang,this.chartInfo.ChartType);
  412. console.log(this.options,'options');
  413. // 散点图
  414. if(this.chartInfo.ChartType == 5){
  415. this.options.yAxis.title.text = this.currentLang == 'zh' ? this.options.yAxis.title.textCh : this.options.yAxis.title.textEn;
  416. this.options.xAxis.title.text = this.currentLang == 'zh' ? this.options.xAxis.title.textCh : this.options.xAxis.title.textEn
  417. this.options.series.forEach(item => {
  418. item.name = this.currentLang == 'zh' ? item.nameCh : item.nameEn;
  419. });
  420. this.options.tooltip.formatter = this.currentLang == 'zh' ? this.options.tooltip.formatterCh : this.options.tooltip.formatterEn;
  421. }else{
  422. // 单位
  423. this.options.yAxis.forEach(item => {
  424. item.title.text = this.currentLang == 'zh' ? item.title.textCh : item.title.textEn;
  425. });
  426. // 图例 名称
  427. if(this.chartInfo.ChartType != 2){
  428. // 季节图 不更改图例名称
  429. this.options.series.forEach(item => {
  430. item.name = this.currentLang == 'zh'
  431. ? item.nameCh
  432. : (item.nameEn||item.nameCh)
  433. });
  434. }
  435. //截面散点 x轴标题
  436. if(this.chartInfo.ChartType === 10){
  437. this.options.xAxis.title.text = this.currentLang == 'zh' ? this.options.xAxis.title.textCh : this.options.xAxis.title.textEn;
  438. this.options.tooltip.formatter = this.currentLang == 'zh' ? this.options.tooltip.formatterCh : this.options.tooltip.formatterEn;
  439. this.options.series.forEach(item => {
  440. if(!item.linkedTo) {
  441. item.data.forEach(point => {
  442. point.dataLabels.format = this.currentLang == 'zh' ? point.dataLabels.formatCh : (point.dataLabels.formatEn||point.dataLabels.formatCh);
  443. point.dataLabels.color = (this.currentLang==='en' && !point.dataLabels.formatEn) ? '#999' : '#333'
  444. })
  445. }
  446. });
  447. }
  448. //柱形图额外设置x轴中英文
  449. this.chartInfo.ChartType ===7 && this.changeBarOptions();
  450. }
  451. },
  452. /* 切换商品价格图中英文 */
  453. changeCommodityLang() {
  454. console.log(this.options)
  455. this.options.yAxis.forEach(item => {
  456. item.title.text = this.currentLang == 'zh' ? item.title.textCh : item.title.textEn
  457. });
  458. //图例
  459. this.options.series.forEach(item => {
  460. item.name = this.currentLang == 'zh' ? item.nameCh : item.nameEn
  461. });
  462. //tooltip
  463. this.options.tooltip.formatter = this.currentLang == 'zh' ? this.options.tooltip.formatterCh : this.options.tooltip.formatterEn
  464. //x轴
  465. this.options.xAxis.categories = this.commodityXData.map(_ => this.currentLang == 'zh' ? _.Name:_.NameEn);
  466. },
  467. /* 切换相关性图中英文 */
  468. changeRelevanceLang(){
  469. this.options.yAxis.forEach(item => {
  470. item.title.text = this.currentLang == 'zh' ? item.title.textCh : item.title.textEn||item.title.textCh
  471. });
  472. //图例
  473. this.options.series.forEach(item => {
  474. item.name = this.currentLang == 'zh' ? item.nameCh : item.nameEn||item.nameCh
  475. });
  476. //tooltip
  477. this.options.tooltip.formatter = this.currentLang == 'zh' ? this.options.tooltip.formatterCh : this.options.tooltip.formatterEn
  478. this.options.xAxis.title.text=this.currentLang == 'zh' ? this.options.xAxis.title.textCh : this.options.xAxis.title.textEn
  479. },
  480. /* ================================================================ */
  481. /* 图表的配置项*/
  482. setChartOptionHandle(newval) {
  483. /* 显示类型 数据结构单独处理 */
  484. const chartSetMap = {
  485. 1: this.setDefaultChart,
  486. 2: this.setSeasonChart,
  487. 3: this.setStackOrCombinChart,
  488. 4: this.setStackOrCombinChart,
  489. 5: this.setScatterChart,
  490. 6: this.setStackOrCombinChart,
  491. };
  492. chartSetMap[this.chartInfo.ChartType]&&chartSetMap[this.chartInfo.ChartType](newval)
  493. //myeta内或者数据指标库内
  494. if(['/mychart','/database','/edbBasicbase'].includes(this.$route.path)) this.showData = true;
  495. },
  496. /* 曲线图设置 */
  497. setDefaultChart(newval) {
  498. /* 上下限显示和值的设置 */
  499. if([4,6,7,8].includes(this.chartInfo.Source)) {
  500. this.leftIndex = -1;
  501. this.rightIndex = -1;
  502. this.rightTwoIndex = -1;
  503. this.chartLimit = {
  504. min:'', //左轴上下限
  505. max:'',
  506. rightMin:'',//右轴上下限
  507. rightMax:'',
  508. rightTwoMin:'',//右二轴上下限
  509. rightTwoMax:'',
  510. };
  511. }else {
  512. this.leftIndex = newval.findIndex((item) => item.IsAxis===1);
  513. this.rightIndex = newval.findIndex((item) => !item.IsAxis);
  514. this.rightTwoIndex = newval.findIndex((item) => item.IsAxis ===2);
  515. }
  516. /* 主题样式*/
  517. const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
  518. //拼接标题 数据列
  519. let data = [];
  520. let ydata = [];
  521. //有右二轴时排个序 按照左 右 右2的顺序
  522. let chartData = newval.some(_ =>_.IsAxis===2) ? this.changeEdbOrder(newval) : _.cloneDeep(newval);
  523. chartData.forEach((item, index) => {
  524. //轴位置值相同的下标
  525. let sameSideIndex = chartData.findIndex(
  526. (i) => i.IsAxis === item.IsAxis
  527. );
  528. //获取对应轴的上下限
  529. //预测指标-走势图;图表配置-主题设置;不使用自定义上下限,剔除
  530. const useTableLimit = ['/predictEdb','/addpredictEdb','/editpredictEdb','/chartThemeSet'].includes(this.$route.path)
  531. //非ETA图库图表也不设置自定义上下限,相关性和统计特征也会用到曲线图
  532. //若chartInfo.Source为1,需在之前调用setLimitData
  533. const isETASource = [1,11,12].includes(this.chartInfo.Source)
  534. let minLimit = 0,maxLimit = 0
  535. if(useTableLimit||!isETASource){
  536. minLimit = newval[sameSideIndex].MinData
  537. maxLimit = newval[sameSideIndex].MaxData
  538. }
  539. if(!useTableLimit&&isETASource){
  540. const limitMap = {
  541. 0:['rightMin','rightMax'],
  542. 1:['min','max'],
  543. 2:['rightTwoMin','rightTwoMax']
  544. }
  545. if(limitMap[item.IsAxis]){
  546. minLimit = this.chartLimit[`${limitMap[item.IsAxis][0]}`]||0
  547. maxLimit = this.chartLimit[`${limitMap[item.IsAxis][1]}`]||0
  548. }
  549. }
  550. //y轴
  551. const textZh =this.chartInfo.Source===12? item.ConvertUnit: item.ConvertUnit||item.Unit
  552. const textEn =this.chartInfo.Source===12? item.ConvertEnUnit:item.ConvertEnUnit||item.UnitEn||item.ConvertUnit||item.Unit
  553. let yItem = {
  554. ...basicYAxis,
  555. title: {
  556. text: textZh,
  557. textCh:textZh, // 中文
  558. // 中文不存在,无论英文有无都显示空
  559. textEn:textZh?textEn:'', // 英文
  560. style:{
  561. ...chartTheme&&chartTheme.yAxisOptions.style
  562. },
  563. align: 'high',
  564. rotation: 0,
  565. y: -12,
  566. x: (item.IsAxis===0 && this.rightTwoIndex>-1) ? -chartData[this.rightTwoIndex].Unit.length*12 : 0,
  567. textAlign: item.IsAxis===1 ? 'left' : 'right',
  568. reserveSpace: false
  569. },
  570. labels: {
  571. formatter: function (ctx) {
  572. return ctx.value;
  573. },
  574. align: 'center',
  575. x: [0,2].includes(item.IsAxis) ? 5 : -5,
  576. style: {
  577. ...chartTheme&&chartTheme.yAxisOptions.style,
  578. }
  579. },
  580. opposite: [0,2].includes(item.IsAxis),
  581. reversed: item.IsOrder,
  582. min: Number(minLimit),
  583. max: Number(maxLimit),
  584. tickWidth: 1,
  585. visible: sameSideIndex === index,
  586. plotBands: this.setAxisPlotAreas(item.IsAxis),
  587. plotLines: this.setAxisPlotLines(item.IsAxis)
  588. };
  589. //拼接标题 判断相同指标名称拼接来源
  590. let dynamic_title = item.EdbName;
  591. let dynamic_arr = chartData.filter(
  592. (item) => dynamic_title === item.EdbName
  593. );
  594. // 拼接配置 IsAxis左轴1 右轴0 右2轴2 IsOrder正序false 逆序true EdbInfoType是否是领先指标
  595. let dynamic_tag = this.concatDynamicTag(item);
  596. let dynamic_tag_en = this.concatDynamicTag(item,'en');
  597. //预测指标配置
  598. let predict_params = item.EdbInfoCategoryType === 1 ? this.getPredictParams(item) : {};
  599. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  600. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  601. //数据列
  602. let obj = {
  603. data: [],
  604. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || 'spline',
  605. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  606. yAxis: sameSideIndex,
  607. name:
  608. dynamic_arr.length > 1
  609. ? `${item.EdbAliasName||item.EdbName}(${item.SourceName})${dynamic_tag}`
  610. : `${item.EdbAliasName||item.EdbName}${dynamic_tag}`,
  611. nameCh:dynamic_arr.length > 1
  612. ? `${item.EdbAliasName||item.EdbName}(${item.SourceName})${dynamic_tag}`
  613. : `${item.EdbAliasName||item.EdbName}${dynamic_tag}`,
  614. nameEn:item.EdbNameEn?`${item.EdbNameEn}${dynamic_tag_en}`:`${item.EdbAliasName||item.EdbName}${dynamic_tag}`,
  615. color: item.ChartColor,
  616. lineWidth:Number(item.ChartWidth)|| (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth)||1,
  617. marker: chartTheme && chartTheme.lineOptionList[lineIndex].dataMark && chartTheme.lineOptionList[lineIndex].dataMark!='none'?{
  618. enabled:true,
  619. symbol: chartTheme.lineOptionList[lineIndex].markType || 'circle',
  620. fillColor:chartTheme.lineOptionList[lineIndex].markColor,
  621. radius: chartTheme.lineOptionList[lineIndex].markSize
  622. }:{},
  623. ...predict_params
  624. };
  625. item.DataList = item.DataList || [];
  626. for (let i of item.DataList) {
  627. obj.data.push([i.DataTimestamp, i.Value]);
  628. }
  629. data.push(obj);
  630. ydata.push(yItem);
  631. });
  632. /* x轴处理 */
  633. let isLessThanOneYear = this.xLabelDealHandle();
  634. let xAxis = {
  635. ...defaultOpts.xAxis,
  636. labels: {
  637. formatter: function (ctx) {
  638. return isLessThanOneYear
  639. ? Highcharts.dateFormat('%m/%d', ctx.value)
  640. : Highcharts.dateFormat('%y/%m', ctx.value);
  641. },
  642. style: {
  643. ...chartTheme&&chartTheme.xAxisOptions.style
  644. }
  645. },
  646. plotBands: this.setAxisPlotAreas(3,'datetime'),
  647. plotLines: this.setAxisPlotLines(3,'datetime')
  648. }
  649. this.options = {
  650. series: data,
  651. yAxis: ydata,
  652. xAxis
  653. };
  654. //滚动相关性独立tooltip
  655. if(this.chartInfo.Source === 4) {
  656. const { LeadValue,LeadUnit } = this.relevanceChartData.CorrelationChartInfo;
  657. let relevanceUnitEnMap = this.relevanceUnitEnMap;
  658. this.options.tooltip = {
  659. formatter: function() {
  660. let str = `${Highcharts.dateFormat('%Y/%m/%d',this.x)}<br><p>相关性系数:${this.y.toFixed(4)}</p><br><p>领先${LeadValue+LeadUnit}</p>`
  661. return str
  662. },
  663. formatterCh: function() {
  664. let str = `${Highcharts.dateFormat('%Y/%m/%d',this.x)}<br><p>相关性系数:${this.y.toFixed(4)}</p><br><p>领先${LeadValue+LeadUnit}</p>`
  665. return str
  666. },
  667. formatterEn: function() {
  668. 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>`
  669. return str
  670. }
  671. }
  672. }
  673. if(this.currentLang=='en') this.changeOptions()
  674. },
  675. /* 堆叠图/组合图设置
  676. 本来和曲线图逻辑基本一致兼容下即可 为了以后便于维护和阅读还是拆开写吧
  677. */
  678. setStackOrCombinChart(newval) {
  679. const chartTypeMap = {
  680. 3: 'areaspline',
  681. 4: 'column',
  682. 6: ''
  683. };
  684. let chartStyle = chartTypeMap[this.chartInfo.ChartType];
  685. /* 主题样式*/
  686. const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
  687. //拼接标题 数据列
  688. let data = [];
  689. let ydata = [];
  690. //有右二轴时排个序 按照左 右 右2的顺序
  691. let chartData = newval.some(_ =>_.IsAxis===2) ? this.changeEdbOrder(newval) : _.cloneDeep(newval);
  692. chartData.forEach((item, index) => {
  693. //轴位置值相同的下标
  694. let sameSideIndex = chartData.findIndex(
  695. (i) => i.IsAxis === item.IsAxis
  696. );
  697. //堆叠图的yAxis必须一致 数据列所对应的y轴
  698. let serie_yIndex = index;
  699. if([3,4].includes(this.chartInfo.ChartType)) {
  700. // 类型为堆叠图时公用第一个指标y轴
  701. serie_yIndex = 0;
  702. } else if(this.chartInfo.ChartType ===6 && ['areaspline','column'].includes(item.ChartStyle)) {
  703. // 组合图找第一个堆叠柱状或面积的作为公用
  704. serie_yIndex = chartData.findIndex(i => i.ChartStyle === item.ChartStyle);
  705. }
  706. //数据对应的y轴是公用轴则配置也共享
  707. item.IsAxis = serie_yIndex === index ? item.IsAxis : chartData[serie_yIndex].IsAxis;
  708. item.IsOrder = serie_yIndex === index ? item.IsOrder : chartData[serie_yIndex].IsOrder;
  709. /* 上下限显示的设置 */
  710. this.leftIndex = [3,4].includes(this.chartInfo.ChartType)
  711. ? (chartData[serie_yIndex].IsAxis ? serie_yIndex : -1)
  712. : newval.findIndex((item) => item.IsAxis===1);
  713. this.rightIndex = [3,4].includes(this.chartInfo.ChartType)
  714. ? (chartData[serie_yIndex].IsAxis ? -1 : serie_yIndex)
  715. : newval.findIndex((item) => !item.IsAxis);
  716. this.rightTwoIndex = [3,4].includes(this.chartInfo.ChartType)
  717. ? -1
  718. : newval.findIndex((item) => item.IsAxis===2);
  719. //获取对应轴的上下限
  720. //预测指标-走势图;图表配置-主题设置;不使用自定义上下限,剔除
  721. const useTableLimit = ['/predictEdb','/chartThemeSet'].includes(this.$route.path)
  722. let minLimit = 0,maxLimit = 0
  723. if(useTableLimit){
  724. minLimit = chartData[sameSideIndex].MinData
  725. maxLimit = chartData[sameSideIndex].MaxData
  726. }else{
  727. const limitMap = {
  728. 0:['rightMin','rightMax'],
  729. 1:['min','max'],
  730. 2:['rightTwoMin','rightTwoMax']
  731. }
  732. if(limitMap[item.IsAxis]){
  733. minLimit = this.chartLimit[`${limitMap[item.IsAxis][0]}`]||0
  734. maxLimit = this.chartLimit[`${limitMap[item.IsAxis][1]}`]||0
  735. }
  736. }
  737. //y轴
  738. const textZh = item.ConvertUnit||item.Unit
  739. const textEn = item.ConvertEnUnit||item.UnitEn||item.ConvertUnit||item.Unit
  740. let yItem = {
  741. ...basicYAxis,
  742. title: {
  743. text: textZh,
  744. textCh:textZh, // 中文
  745. // 中文不存在,无论英文有无都显示空
  746. textEn:textZh?textEn:'', // 英文
  747. style:{
  748. ...chartTheme&&chartTheme.yAxisOptions.style
  749. },
  750. align: 'high',
  751. rotation: 0,
  752. y: -12,
  753. x: (item.IsAxis===0 && this.rightTwoIndex>-1) ? -chartData[this.rightTwoIndex].Unit.length*12 : 0,
  754. textAlign: item.IsAxis===1 ? 'left' : 'right',
  755. reserveSpace: false
  756. },
  757. labels: {
  758. formatter: function (ctx) {
  759. return ctx.value;
  760. },
  761. align: 'center',
  762. x: [0,2].includes(item.IsAxis) ? 5 : -5,
  763. style: {
  764. ...chartTheme&&chartTheme.yAxisOptions.style
  765. }
  766. },
  767. opposite: [0,2].includes(item.IsAxis),
  768. reversed: item.IsOrder,
  769. min: Number(minLimit),
  770. max: Number(maxLimit),
  771. tickWidth: 1,
  772. visible: serie_yIndex === index && sameSideIndex ===index,
  773. plotBands: this.setAxisPlotAreas(item.IsAxis),
  774. plotLines: this.setAxisPlotLines(item.IsAxis)
  775. };
  776. //拼接标题 判断相同指标名称拼接来源
  777. let dynamic_title = item.EdbName;
  778. let dynamic_arr = chartData.filter(
  779. (item) => dynamic_title === item.EdbName
  780. );
  781. // 拼接配置 IsAxis左轴1 右轴0 IsOrder正序false 逆序true EdbInfoType是否是领先指标
  782. let dynamic_tag = this.concatDynamicTag(item);
  783. let dynamic_tag_en = this.concatDynamicTag(item,'en');
  784. //预测指标配置
  785. let predict_params = item.EdbInfoCategoryType === 1 ? this.getPredictParams(item,chartStyle) : {};
  786. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  787. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  788. //数据列
  789. let obj = {
  790. data: [],
  791. type: chartStyle || item.ChartStyle,
  792. yAxis: serie_yIndex,
  793. name:
  794. dynamic_arr.length > 1
  795. ? `${item.EdbAliasName||item.EdbName}(${item.SourceName})${dynamic_tag}`
  796. : `${item.EdbAliasName||item.EdbName}${dynamic_tag}`,
  797. nameCh:dynamic_arr.length > 1
  798. ? `${item.EdbAliasName||item.EdbName}(${item.SourceName})${dynamic_tag}`
  799. : `${item.EdbAliasName||item.EdbName}${dynamic_tag}`,
  800. nameEn:item.EdbNameEn?`${item.EdbNameEn}${dynamic_tag_en}`:`${item.EdbAliasName||item.EdbName}${dynamic_tag}`,
  801. color: item.ChartColor,
  802. lineWidth: Number(item.ChartWidth)||(chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 1,
  803. fillColor: (this.chartInfo.ChartType === 3 || (this.chartInfo.ChartType === 6 && item.ChartStyle === 'areaspline')) ? item.ChartColor : undefined,
  804. borderWidth: 1,
  805. borderColor: item.ChartColor,
  806. zIndex: (this.chartInfo.ChartType === 6 && ['line','spline'].includes(item.ChartStyle)) ? 1 : 0, //防止组合图曲线被遮住
  807. ...predict_params,
  808. stacking:this.chartInfo.ChartType==6&&!this.IsHeap?undefined:'normal',
  809. };
  810. item.DataList = item.DataList || [];
  811. for (let i of item.DataList) {
  812. obj.data.push([i.DataTimestamp, i.Value]);
  813. }
  814. console.log(obj,'obj');
  815. data.push(obj);
  816. ydata.push(yItem);
  817. });
  818. let isLessThanOneYear = this.xLabelDealHandle();
  819. let xAxis = {
  820. ...defaultOpts.xAxis,
  821. labels: {
  822. formatter: function (ctx) {
  823. return isLessThanOneYear
  824. ? Highcharts.dateFormat('%m/%d', ctx.value)
  825. : Highcharts.dateFormat('%y/%m', ctx.value);
  826. },
  827. style: {
  828. ...chartTheme&&chartTheme.xAxisOptions.style
  829. }
  830. },
  831. plotBands: this.setAxisPlotAreas(3,'datetime'),
  832. plotLines: this.setAxisPlotLines(3,'datetime')
  833. }
  834. this.options = {
  835. series: data,
  836. yAxis: ydata,
  837. xAxis,
  838. };
  839. if(this.currentLang=='en') this.changeOptions()
  840. },
  841. /* 季节图设置 农历 公历 */
  842. setSeasonChart(newval) {
  843. /* 季节性图的图表配置 */
  844. this.leftIndex = 0;
  845. const {SeasonRightConfig={}} = this.chartInfo
  846. this.rightIndex = SeasonRightConfig.IsShow?1:-1;
  847. this.rightTwoIndex = -1;
  848. const chartData = newval[0];
  849. // 农历数据需要去除第一项 农历和公历处理逻辑一样
  850. /**
  851. * isPredictorChart - 预测指标的chartInfo.vue组件内定义的变量
  852. * 预测指标成图 还是之前农历图的逻辑,有空再拆吧,做个兼容
  853. */
  854. const chartDataHandle=this.calendar_type === '农历'?
  855. this.isPredictorChart?chartData.DataList.List.filter((item, index) => index > 0):
  856. chartData.DataList.filter((item, index) => index > 0):
  857. chartData.DataList||[]
  858. /* 主题样式*/
  859. const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
  860. // 跟颜色对应
  861. chartTheme && (chartTheme.lineOptionList=chartTheme.lineOptionList.reverse().slice(-chartDataHandle.length))
  862. let seasonYdata = [],
  863. seasonData = [];
  864. //获取对应轴的上下限
  865. //预测指标-走势图;图表配置-主题设置;不使用自定义上下限,剔除
  866. const useTableLimit = ['/predictEdb','/chartThemeSet','/addpredictEdb','/editpredictEdb','/viewBalanceSheet','/editBalanceSheet'].includes(this.$route.path)
  867. let minLimit = 0,maxLimit = 0,rightMin=0,rightMax=0
  868. if(useTableLimit){
  869. minLimit = chartData.MinData
  870. maxLimit = chartData.MaxData
  871. //这几个页面的季节性图没有右轴,若有,取SearonRightConfig.EdbInfoList[0]的MinData/MaxData
  872. }else{
  873. minLimit = this.chartLimit.min||0
  874. maxLimit = this.chartLimit.max||0
  875. //加上右轴
  876. if(this.rightIndex!=-1){
  877. rightMin = this.chartLimit.rightMin||0
  878. rightMax = this.chartLimit.rightMax||0
  879. }
  880. }
  881. //数据列-常规左轴
  882. for (let index in chartDataHandle) {
  883. let j = chartDataHandle[index]
  884. //预测指标配置
  885. let predict_params = chartData.EdbInfoCategoryType === 1 ? this.getSeasonPredictParams(j.CuttingDataTimestamp) : {};
  886. // 图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  887. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  888. let serie_item = {
  889. data: [],
  890. type: (chartTheme && chartTheme.lineOptionList[lineIndex].lineType) || chartData.ChartStyle,
  891. dashStyle: (chartTheme && chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  892. yAxis: 0,
  893. name: this.isPredictorChart?j.Year:j.ChartLegend,
  894. lineWidth: (chartTheme && chartTheme.lineOptionList[lineIndex].lineWidth) || 1,
  895. marker: chartTheme && chartTheme.lineOptionList[lineIndex].dataMark && chartTheme.lineOptionList[lineIndex].dataMark!='none'?{
  896. enabled:true,
  897. symbol: chartTheme.lineOptionList[lineIndex].markType || 'circle',
  898. fillColor:chartTheme.lineOptionList[lineIndex].markColor,
  899. radius: chartTheme.lineOptionList[lineIndex].markSize
  900. }:{},
  901. ...predict_params
  902. };
  903. const data_array = this.calendar_type === '农历' && this.isPredictorChart?_.cloneDeep(j.Items):_.cloneDeep(j.DataList);
  904. data_array && data_array.forEach((item) => {
  905. serie_item.data.push([item.DataTimestamp, item.Value]);
  906. });
  907. seasonData.push(serie_item);
  908. }
  909. //数据列-同期上下限/均线/标准差
  910. const {MaxMinLimits={},SamePeriodAverage={},SamePeriodStandardDeviation={}} = this.chartInfo.SeasonAverageConfig||{}
  911. if(MaxMinLimits.IsShow&&MaxMinLimits.List&&MaxMinLimits.List.length){
  912. let serieItem = {
  913. type:'arearange',//上下限是一个范围
  914. data:[],
  915. name:MaxMinLimits.Legend||'同期上下限',
  916. color:MaxMinLimits.Color||'#075EEE' ,
  917. fillOpacity:parseRgbaColor(MaxMinLimits.Color||'')>0.75?0.75:parseRgbaColor(MaxMinLimits.Color||'') //透明度最高0.75
  918. }
  919. MaxMinLimits.List.forEach(item=>{
  920. serieItem.data.push([item.DataTimestamp,item.MinValue,item.MaxValue])
  921. })
  922. seasonData.push(serieItem)
  923. }
  924. if(SamePeriodAverage.IsShow&&SamePeriodAverage.List){
  925. let serieItem = {
  926. type:'line',
  927. data:[],
  928. lineWidth:SamePeriodAverage.LineWidth,
  929. dashStyle:SamePeriodAverage.LineType,
  930. name:SamePeriodAverage.Legend||'同期均值',
  931. color:SamePeriodAverage.Color||'#075EEE'
  932. }
  933. SamePeriodAverage.List.forEach(item=>{
  934. serieItem.data.push([item.DataTimestamp,item.Value])
  935. })
  936. seasonData.push(serieItem)
  937. }
  938. if(SamePeriodStandardDeviation.IsShow&&SamePeriodStandardDeviation.List){
  939. let serieItem = {
  940. type:'arearange',//标准差也是一个范围
  941. data:[],
  942. name:SamePeriodStandardDeviation.Legend||'同期标准差',
  943. color:SamePeriodStandardDeviation.Color||'#075EEE',
  944. fillOpacity:parseRgbaColor(SamePeriodStandardDeviation.Color||'')>0.75?0.75:parseRgbaColor(SamePeriodStandardDeviation.Color||'')
  945. }
  946. SamePeriodStandardDeviation.List.forEach(item=>{
  947. serieItem.data.push([item.DataTimestamp,item.MinValue,item.MaxValue])
  948. })
  949. seasonData.push(serieItem)
  950. }
  951. //数据列-右轴
  952. if(SeasonRightConfig.IsShow){
  953. //右轴的设置
  954. let serieConfig = SeasonRightConfig.Style==='column'?{
  955. //柱形
  956. type:'column',
  957. color:SeasonRightConfig.ChartColor
  958. }:{
  959. //标记点
  960. type:'spline',
  961. lineWidth:SeasonRightConfig.LineWidth,
  962. dashStyle:SeasonRightConfig.LineStyle,
  963. color:SeasonRightConfig.IsConnected?SeasonRightConfig.LineColor:'rgba(255, 255, 255, 0)',//没有连线颜色设置为透明
  964. marker:{
  965. enabled:true,
  966. symbol:SeasonRightConfig.Shape,
  967. fillColor:SeasonRightConfig.ChartColor,
  968. radius:SeasonRightConfig.Size
  969. },
  970. }
  971. let serieItem = {
  972. ...serieConfig,
  973. name:SeasonRightConfig.Legend||'',
  974. data:[],
  975. yAxis:1,
  976. }
  977. const DataList = (SeasonRightConfig.IndicatorType===1?SeasonRightConfig.EdbInfoList[0].DataList:newval[1].DataList)||[]
  978. DataList.forEach(item=>{
  979. serieItem.data.push([item.DataTimestamp,item.Value])
  980. })
  981. seasonData.push(serieItem)
  982. }
  983. //y轴
  984. const textZh = chartData.ConvertUnit||chartData.Unit
  985. const textEn = chartData.ConvertEnUnit||chartData.UnitEn||chartData.ConvertUnit||chartData.Unit
  986. seasonYdata = [{
  987. ...seasonOptions.yAxis,
  988. labels: {
  989. formatter: function () {
  990. let val = this.value;
  991. return val;
  992. },
  993. align: 'center',
  994. style: {
  995. ...chartTheme&&chartTheme.yAxisOptions.style
  996. }
  997. },
  998. title: {
  999. text: `${textZh}`,
  1000. textCh:textZh, // 中文
  1001. // 中文不存在,无论英文有无都显示空
  1002. textEn:textZh?textEn:'', // 英文
  1003. style:{
  1004. ...chartTheme&&chartTheme.yAxisOptions.style
  1005. },
  1006. // text: null,
  1007. align: 'high',
  1008. rotation: 0,
  1009. y: -12,
  1010. x: 0,
  1011. textAlign: 'left',
  1012. reserveSpace: false
  1013. },
  1014. max: Number(maxLimit),
  1015. min: Number(minLimit),
  1016. plotBands: this.setAxisPlotAreas(1),
  1017. plotLines: this.setAxisPlotLines(1)
  1018. }];
  1019. //如果有右轴,seasonYdata加上右轴
  1020. if(SeasonRightConfig.IsShow){
  1021. const rightEdb = (SeasonRightConfig.IndicatorType===1?SeasonRightConfig.EdbInfoList[0]:newval[1])||{Unit:''}
  1022. //左轴同比:text为空或% 右轴指标:取指标单位
  1023. if(SeasonRightConfig.IndicatorType===1){
  1024. rightEdb.Unit = SeasonRightConfig.NumFormat===1?'%':''
  1025. }else{
  1026. rightEdb.Unit = newval[1]&&(newval[1].ConvertUnit||newval[1].Unit)||''
  1027. }
  1028. seasonYdata.push({
  1029. ...seasonOptions.yAxis,
  1030. opposite: true,//右轴
  1031. labels: {
  1032. formatter: function () {
  1033. let val = this.value;
  1034. return val;
  1035. },
  1036. align: 'center',
  1037. style: {
  1038. ...chartTheme&&chartTheme.yAxisOptions.style
  1039. }
  1040. },
  1041. title: {
  1042. text: rightEdb.Unit||'',
  1043. style:{
  1044. ...chartTheme&&chartTheme.yAxisOptions.style
  1045. },
  1046. align: 'high',
  1047. rotation: 0,
  1048. y: -12,
  1049. x: -rightEdb.Unit.length*12 ,
  1050. textAlign: 'right',
  1051. reserveSpace: false,
  1052. },
  1053. max: Number(rightMax),
  1054. min: Number(rightMin),
  1055. })
  1056. }
  1057. /* x轴显示月日 */
  1058. const xAxis = {
  1059. ...defaultOpts.xAxis,
  1060. labels: {
  1061. formatter: function () {
  1062. return Highcharts.dateFormat('%m/%d', this.value);
  1063. },
  1064. style: {
  1065. ...chartTheme&&chartTheme.xAxisOptions.style
  1066. }
  1067. },
  1068. plotBands: this.setAxisPlotAreas(3,'datetime'),
  1069. plotLines: this.setAxisPlotLines(3,'datetime')
  1070. }
  1071. const tooltip = {
  1072. ...defaultOpts.tooltip,
  1073. dateTimeLabelFormats: {
  1074. // 时间格式化字符
  1075. day: '%m/%d',
  1076. week: '%m/%d',
  1077. month: '%m/%d',
  1078. year: '%m/%d',
  1079. },
  1080. xDateFormat: '%m/%d',
  1081. }
  1082. let colors = chartTheme&&chartTheme.colorsOptions.reverse()||seasonOptions.colors;
  1083. // 季节性 农历成图老逻辑,需要截取 指标成图还在用,后面需要统一或者拆分
  1084. let rangeSelector =
  1085. this.calendar_type === '农历' && this.isPredictorChart
  1086. ? {
  1087. enabled: true,
  1088. selected: 0,
  1089. inputStyle: {
  1090. display: 'none',
  1091. },
  1092. labelStyle: {
  1093. display: 'none',
  1094. },
  1095. buttonTheme: {
  1096. style: {
  1097. display: 'none',
  1098. },
  1099. },
  1100. buttons: [
  1101. {
  1102. type: 'month',
  1103. count: 12,
  1104. text: '12月',
  1105. },
  1106. {
  1107. type: 'month',
  1108. count: 15,
  1109. text: '15月',
  1110. },
  1111. {
  1112. type: 'all',
  1113. text: '全部',
  1114. type: 'all',
  1115. },
  1116. ],
  1117. }
  1118. : {
  1119. enabled: false,
  1120. };
  1121. console.log('季节图配置');
  1122. this.options = {
  1123. colors: colors.slice(-chartDataHandle.length),
  1124. series: seasonData,
  1125. yAxis: seasonYdata,
  1126. xAxis,
  1127. rangeSelector,
  1128. tooltip
  1129. };
  1130. if(this.currentLang=='en') this.changeOptions()
  1131. },
  1132. /* 散点图设置 只允许2指标画图第一个指标值为x轴 第二个指标为y轴 */
  1133. setScatterChart(newval) {
  1134. console.log(newval);
  1135. this.leftIndex = 1;
  1136. this.rightIndex = -1;
  1137. this.rightTwoIndex = -1;
  1138. if(newval.length !== 2) {
  1139. this.leftIndex = -1
  1140. this.options = {}
  1141. return
  1142. };
  1143. console.log('===========:',this.isSetExtremeValue)
  1144. /* 主题样式*/
  1145. const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
  1146. // 取2个指标中日期相同的数据
  1147. let real_data = [];
  1148. let tmpData_date = {};//用来取点对应的日期
  1149. let data1 = _.cloneDeep(newval)[0].DataList || [];
  1150. let data2 = _.cloneDeep(newval)[1].DataList || [];
  1151. data1.forEach(_item => {
  1152. data2.forEach(_item2 => {
  1153. if(_item.DataTimestamp === _item2.DataTimestamp) {
  1154. _item.DataTime = _item.DataTime.replace(/-/g,'/');
  1155. //日期
  1156. let itemIndex =_item.Value + "_" +_item2.Value
  1157. if(tmpData_date[itemIndex]) {
  1158. tmpData_date[itemIndex].push(_item.DataTime)
  1159. } else {
  1160. tmpData_date[itemIndex] = [_item.DataTime]
  1161. }
  1162. //值
  1163. real_data.push({
  1164. x: _item.Value,
  1165. y: _item2.Value
  1166. })
  1167. }
  1168. })
  1169. })
  1170. real_data.sort((x,y) => x-y);
  1171. //悬浮窗 拼接日期 原始指标名称
  1172. let tooltip = {
  1173. formatter: function() {
  1174. 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>
  1175. ${newval[0].EdbName}: <span style="font-weight: 600"> ${this.x}</span><br>
  1176. ${newval[1].EdbName}: <span style="font-weight: 600"> ${this.y}</span>
  1177. `
  1178. },
  1179. // 中文
  1180. formatterCh: function() {
  1181. 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>
  1182. ${newval[0].EdbName}: <span style="font-weight: 600"> ${this.x}</span><br>
  1183. ${newval[1].EdbName}: <span style="font-weight: 600"> ${this.y}</span>
  1184. `
  1185. },
  1186. // 英文
  1187. formatterEn: function() {
  1188. let str1 = newval[0].EdbNameEn||newval[0].EdbName;
  1189. let str2 = newval[1].EdbNameEn||newval[1].EdbName;
  1190. 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>
  1191. ${str1}: <span style="font-weight: 600"> ${this.x}</span><br>
  1192. ${str2}: <span style="font-weight: 600"> ${this.y}</span>
  1193. `
  1194. }
  1195. }
  1196. //获取对应轴的上下限
  1197. //预测指标-走势图;图表配置-主题设置;不使用自定义上下限,剔除
  1198. const useTableLimit = ['/predictEdb','/chartThemeSet'].includes(this.$route.path)
  1199. let minLimit = 0,maxLimit = 0
  1200. if(useTableLimit){
  1201. minLimit = Math.min(...real_data.map(_ => _.y));
  1202. maxLimit = Math.max(...real_data.map(_ => _.y));
  1203. }else{
  1204. minLimit = this.chartLimit.min||0
  1205. maxLimit = this.chartLimit.max||0
  1206. }
  1207. const { IsOrder,ChartColor } = newval[0];
  1208. //y轴
  1209. const textYZh = newval[1].ConvertUnit||newval[1].Unit
  1210. const textYEn = newval[1].ConvertEnUnit||newval[1].UnitEn||newval[1].ConvertUnit||newval[1].Unit
  1211. let yAxis = {
  1212. ...basicYAxis,
  1213. title: {
  1214. text: `${textYZh}`,
  1215. textCh:textYZh,// 中文
  1216. // 中文不存在,无论英文有无都显示空
  1217. textEn:textYZh?textYEn:'', // 英文
  1218. style:{
  1219. ...chartTheme&&chartTheme.yAxisOptions.style
  1220. },
  1221. align: 'high',
  1222. rotation: 0,
  1223. y: -12,
  1224. x:0,
  1225. textAlign: 'left',
  1226. reserveSpace: false
  1227. },
  1228. labels: {
  1229. formatter: function (ctx) {
  1230. let val = ctx.value;
  1231. return val;
  1232. },
  1233. align: 'center',
  1234. style:{
  1235. ...chartTheme&&chartTheme.yAxisOptions.style
  1236. },
  1237. },
  1238. opposite: false,
  1239. reversed: IsOrder,
  1240. min: Number(minLimit),
  1241. max: Number(maxLimit),
  1242. tickWidth: 1,
  1243. plotBands: this.setAxisPlotAreas(1),
  1244. plotLines: this.setAxisPlotLines(1)
  1245. }
  1246. //x轴
  1247. const textXZh = newval[0].ConvertUnit||newval[0].Unit
  1248. const textXEn = newval[0].ConvertEnUnit||newval[0].UnitEn||newval[0].ConvertUnit||newval[0].Unit
  1249. const xAxis = {
  1250. ...scatterXAxis,
  1251. title: {
  1252. text: `${textXZh}`,
  1253. textCh:textXZh, // 中文
  1254. // 中文不存在,无论英文有无都显示空
  1255. textEn:textXZh?textXEn:'', // 英文
  1256. style: {
  1257. ...chartTheme&&chartTheme.xAxisOptions.style
  1258. },
  1259. align: 'high',
  1260. rotation: 0,
  1261. x: 0,
  1262. offset: 20,
  1263. },
  1264. labels: {
  1265. style: {
  1266. ...chartTheme&&chartTheme.xAxisOptions.style
  1267. }
  1268. },
  1269. plotBands: this.setAxisPlotAreas(3),
  1270. plotLines: this.setAxisPlotLines(3)
  1271. }
  1272. //数据列
  1273. let series = {
  1274. data: [],
  1275. type: 'scatter',
  1276. name: `${this.chartInfo.ChartName}${IsOrder ? '(逆序)' : ''}`,
  1277. nameCh: `${this.chartInfo.ChartName}${IsOrder ? '(逆序)' : ''}`,
  1278. nameEn: `${this.chartInfo.ChartNameEn||this.chartInfo.ChartName}${IsOrder ? '(reverse)' : ''}`,
  1279. color: ChartColor,
  1280. chartType: 'linear',
  1281. marker: {
  1282. radius: (chartTheme&&chartTheme.lineOptionList[0].radius)||5,
  1283. },
  1284. }
  1285. real_data.forEach(_ => {
  1286. series.data.push([_.x,_.y])
  1287. })
  1288. this.options = {
  1289. title: {
  1290. text:''
  1291. },
  1292. series: [ series ],
  1293. yAxis,
  1294. xAxis,
  1295. tooltip
  1296. }
  1297. if(this.currentLang=='en') this.changeOptions()
  1298. },
  1299. /* 奇怪柱状图 和以上逻辑无公用点 依赖数据为单独的数据
  1300. x轴为指标名称的柱形图 以日期作为series
  1301. */
  1302. setBarChart() {
  1303. this.leftIndex = -1;
  1304. this.rightIndex = -1;
  1305. this.rightTwoIndex = -1;
  1306. let seriesData = [];
  1307. const data = _.cloneDeep(this.barDateList);
  1308. /* 主题样式*/
  1309. const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
  1310. //x轴
  1311. let xAxis = {
  1312. ...scatterXAxis,
  1313. categories: this.barXData,
  1314. tickWidth: 1,
  1315. labels: {
  1316. style: {
  1317. ...chartTheme&&chartTheme.xAxisOptions.style
  1318. }
  1319. }
  1320. }
  1321. const { max,min } = this.chartLimit;
  1322. console.log(max,min)
  1323. //y轴
  1324. let yAxis = {
  1325. ...basicYAxis,
  1326. title: {
  1327. text: this.chartInfo.Unit,
  1328. textCh: this.chartInfo.Unit,
  1329. textEn: this.chartInfo.UnitEn,
  1330. align: 'high',
  1331. rotation: 0,
  1332. y: -12,
  1333. x:0,
  1334. textAlign: 'left',
  1335. reserveSpace: false,
  1336. style:{
  1337. ...chartTheme&&chartTheme.yAxisOptions.style
  1338. },
  1339. },
  1340. labels: {
  1341. formatter: function (ctx) {
  1342. let val = ctx.value;
  1343. return val;
  1344. },
  1345. align: 'center',
  1346. style:{
  1347. ...chartTheme&&chartTheme.yAxisOptions.style
  1348. },
  1349. },
  1350. min: Number(min),
  1351. max: Number(max),
  1352. opposite: false,
  1353. tickWidth: 1,
  1354. plotBands: this.setAxisPlotAreas(1),
  1355. plotLines: this.setAxisPlotLines(1)
  1356. }
  1357. //数据列
  1358. data.forEach(item => {
  1359. let serie_item = {
  1360. data: item.Value,
  1361. type: 'column',
  1362. yAxis: 0,
  1363. name: item.Name || item.Date,
  1364. nameCh: item.Name || item.Date,
  1365. nameEn: item.Date,
  1366. color: item.Color,
  1367. chartType: 'linear'
  1368. };
  1369. seriesData.push(serie_item)
  1370. })
  1371. this.options = {
  1372. title: {
  1373. text:''
  1374. },
  1375. plotOptions: {
  1376. column:{
  1377. stacking: null,
  1378. },
  1379. },
  1380. series: seriesData,
  1381. yAxis: [ yAxis ],
  1382. xAxis
  1383. }
  1384. this.currentLang=='en' && this.changeOptions();
  1385. },
  1386. /* 商品价格曲线设置 绘图逻辑同奇怪柱形图*/
  1387. setCommodityChart() {
  1388. //上下限都不通用
  1389. this.leftIndex = -1;
  1390. this.rightIndex = -1;
  1391. this.rightTwoIndex = -1;
  1392. let seriesData = [];
  1393. const data = _.cloneDeep(this.commodityChartData);
  1394. /* 主题样式*/
  1395. const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
  1396. //x轴
  1397. let xAxis = {
  1398. ...scatterXAxis,
  1399. categories: this.commodityXData.filter(_=>_.IsHide===0).map(_ =>_.Name),
  1400. tickWidth: 1,
  1401. labels: {
  1402. style: {
  1403. ...chartTheme&&chartTheme.xAxisOptions.style
  1404. }
  1405. }
  1406. }
  1407. const { max,min } = this.chartLimit;
  1408. //y轴
  1409. let yAxis = {
  1410. ...basicYAxis,
  1411. title: {
  1412. text: this.commodityEdbList[0].Unit,
  1413. textCh: this.commodityEdbList[0].Unit,
  1414. textEn: this.commodityEdbList[0].UnitEn||this.commodityEdbList[0].Unit,
  1415. style:{
  1416. ...chartTheme&&chartTheme.yAxisOptions.style
  1417. },
  1418. align: 'high',
  1419. rotation: 0,
  1420. y: -12,
  1421. textAlign: 'left',
  1422. reserveSpace: false
  1423. },
  1424. labels: {
  1425. formatter: function (ctx) {
  1426. let val = ctx.value;
  1427. return val;
  1428. },
  1429. align: 'center',
  1430. style:{
  1431. ...chartTheme&&chartTheme.yAxisOptions.style
  1432. },
  1433. },
  1434. min: Number(min),
  1435. max: Number(max),
  1436. opposite: false,
  1437. tickWidth: 1,
  1438. }
  1439. //数据列
  1440. data.forEach((item,index) => {
  1441. //处理首或/尾全是无效数据的以null填充
  1442. let filterData = this.filterInvalidData(item)
  1443. // console.log(filterData)
  1444. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  1445. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  1446. let serie_item = {
  1447. data: filterData,
  1448. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || 'spline',
  1449. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  1450. yAxis: 0,
  1451. name: item.Name,
  1452. nameCh: item.Name,
  1453. nameEn: item.NameEn,
  1454. color: item.Color,
  1455. chartType: 'linear',
  1456. lineWidth: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 3,
  1457. marker: {
  1458. enabled: false
  1459. }
  1460. };
  1461. seriesData.push(serie_item)
  1462. })
  1463. //tooltip
  1464. let commodityEdbList = this.commodityEdbList;
  1465. let commodityXData = this.commodityXData;
  1466. let chartInfo = this.chartInfo;
  1467. let tooltip = {
  1468. formatter: function() {
  1469. let str = '';
  1470. this.points.forEach(item => {
  1471. let obj_item = data.find(_ => _.Name === item.series.name);
  1472. let index = commodityXData.findIndex(_ => _.Name === this.x);
  1473. //合约显示
  1474. let haveContract = obj_item.XEdbInfoIdList[index];
  1475. if(haveContract) {
  1476. // 利润曲线指标名
  1477. const isEdb=commodityEdbList.some(_=>_.EdbInfoId===haveContract)
  1478. let edb_name = chartInfo.Source === 5
  1479. ? (isEdb ? obj_item.NameList[index] : `${chartInfo.ProfitName}(${obj_item.NameList[index]})`)
  1480. : commodityEdbList.find(_ => _.EdbInfoId === obj_item.XEdbInfoIdList[index]).EdbName;
  1481. str+=`<b>${ edb_name }</b>`
  1482. if(!obj_item.NoDataEdbList.includes(obj_item.XEdbInfoIdList[index])) {
  1483. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: ${item.y}<br>`
  1484. }else {
  1485. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: 无<br>`
  1486. }
  1487. }
  1488. })
  1489. return str||'无合约'
  1490. },
  1491. formatterCh: function() {
  1492. let str = '';
  1493. this.points.forEach(item => {
  1494. let obj_item = data.find(_ => _.Name === item.series.name);
  1495. let index = commodityXData.findIndex(_ => _.Name === this.x);
  1496. //合约显示
  1497. let haveContract = obj_item.XEdbInfoIdList[index];
  1498. if(haveContract) {
  1499. // 利润曲线指标名
  1500. const isEdb=commodityEdbList.some(_=>_.EdbInfoId===haveContract)
  1501. let edb_name = chartInfo.Source === 5
  1502. ? (isEdb? obj_item.NameList[index] : `${chartInfo.ProfitName}(${obj_item.NameList[index]})`)
  1503. : commodityEdbList.find(_ => _.EdbInfoId === obj_item.XEdbInfoIdList[index]).EdbName;
  1504. str+=`<b>${ edb_name }</b>`
  1505. if(!obj_item.NoDataEdbList.includes(obj_item.XEdbInfoIdList[index])) {
  1506. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: ${item.y}<br>`
  1507. }else {
  1508. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: 无<br>`
  1509. }
  1510. }
  1511. })
  1512. return str||'无合约'
  1513. },
  1514. formatterEn: function() {
  1515. let str = '';
  1516. this.points.forEach(item => {
  1517. let obj_item = data.find(_ => _.NameEn === item.series.name);
  1518. let index = commodityXData.findIndex(_ => _.NameEn === this.x);
  1519. //合约显示
  1520. let haveContract = obj_item.XEdbInfoIdList[index];
  1521. if(haveContract) {
  1522. // 利润曲线指标名
  1523. const isEdb=commodityEdbList.some(_=>_.EdbInfoId===haveContract)
  1524. let edb_name = chartInfo.Source === 5
  1525. ? (isEdb ? obj_item.NameList[index] : `${chartInfo.ProfitNameEn}(${obj_item.NameList[index]})`)
  1526. : commodityEdbList.find(_ => _.EdbInfoId === obj_item.XEdbInfoIdList[index]).EdbNameEn;
  1527. str+=`<b>${ edb_name }</b>`
  1528. if(!obj_item.NoDataEdbList.includes(obj_item.XEdbInfoIdList[index])) {
  1529. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: ${item.y}<br>`
  1530. }else {
  1531. str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: 无<br>`
  1532. }
  1533. }
  1534. })
  1535. return str||'无合约'
  1536. },
  1537. shared: true,
  1538. }
  1539. this.options = {
  1540. title: {
  1541. text:''
  1542. },
  1543. series: seriesData,
  1544. yAxis: [ yAxis ],
  1545. xAxis,
  1546. tooltip
  1547. }
  1548. this.currentLang==='en' && this.changeCommodityLang();
  1549. },
  1550. /* 处理无效数据为null */
  1551. filterInvalidData(item) {
  1552. //找出第一个有效数据和最后一个有效数据的index index1 index2
  1553. //0到index1全填null index2到最后一个全为null
  1554. let validateArr = item.XEdbInfoIdList.filter(_ =>_&&!item.NoDataEdbList.includes(_));
  1555. let first_index = item.XEdbInfoIdList.findIndex(_ => _ === validateArr[0]);
  1556. let last_index = item.XEdbInfoIdList.findIndex(_ => _ === validateArr[validateArr.length-1]);
  1557. console.log('first_index',first_index)
  1558. console.log('last_index',last_index)
  1559. let arr = item.Value.map((item,index) => {
  1560. if(index < first_index || index > last_index) {
  1561. return null
  1562. }else {
  1563. return item
  1564. }
  1565. })
  1566. // 根据设置的x轴显示隐藏去除值
  1567. let temArr=[]
  1568. this.commodityXData.forEach((i,index)=>{
  1569. if(i.IsHide!==1){
  1570. temArr.push(arr[index])
  1571. }
  1572. })
  1573. return temArr;
  1574. },
  1575. /* 获取图表详情后赋值柱状图数据 */
  1576. initBarData(data) {
  1577. const { XEdbIdValue,YDataList,EdbInfoList,ChartInfo } = data;
  1578. let xData = XEdbIdValue.map(_ => EdbInfoList.find(edb => edb.EdbInfoId===_).EdbAliasName)
  1579. this.leftIndex = -1;
  1580. this.rightIndex = -1;
  1581. this.rightTwoIndex = -1;
  1582. this.barXIdList = XEdbIdValue;
  1583. this.barDateList = YDataList;
  1584. this.barXData = xData;
  1585. this.barEdbData = EdbInfoList;
  1586. this.chartLimit = {
  1587. min: Number(ChartInfo.LeftMin),
  1588. max: Number(ChartInfo.LeftMax)
  1589. }
  1590. },
  1591. /* 商品价格曲线获取详情赋值 */
  1592. initCommodityData(data) {
  1593. const { XDataList,YDataList,EdbInfoList,ChartInfo,DataResp } = data;
  1594. this.commodityEdbList = EdbInfoList;
  1595. this.commodityChartData = ChartInfo.Source===5?DataResp.YDataList:YDataList;
  1596. this.commodityXData = ChartInfo.Source===5?DataResp.XDataList:XDataList;
  1597. this.chartLimit = {
  1598. min: Number(ChartInfo.LeftMin),
  1599. max: Number(ChartInfo.LeftMax)
  1600. }
  1601. this.setCommodityChart()
  1602. },
  1603. /* 相关性图表初始化 source4 滚动相关性*/
  1604. initRelevanceChartData(){
  1605. this.leftIndex = -1;
  1606. this.rightIndex = -1;
  1607. this.rightTwoIndex = -1;
  1608. /* 主题样式*/
  1609. const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
  1610. // 处理X轴
  1611. let xAxis={
  1612. categories: this.relevanceChartData.XEdbIdValue,
  1613. tickWidth: 1,
  1614. title: {
  1615. text: this.relevanceChartData.ChartInfo.Source===3 ?`期数(${this.relevanceChartData.CorrelationChartInfo.LeadUnit})` : null,
  1616. textCh:this.relevanceChartData.ChartInfo.Source===3 ? `期数(${this.relevanceChartData.CorrelationChartInfo.LeadUnit})`:null,
  1617. textEn:this.relevanceChartData.ChartInfo.Source===3 ? `stage(${this.relevanceUnitEnMap[this.relevanceChartData.CorrelationChartInfo.LeadUnit]})`:null,
  1618. align: 'high',
  1619. rotation: 0,
  1620. style: {
  1621. ...chartTheme&&chartTheme.xAxisOptions.style
  1622. }
  1623. },
  1624. labels: {
  1625. style: {
  1626. ...chartTheme&&chartTheme.xAxisOptions.style
  1627. }
  1628. },
  1629. tickInterval: 1,
  1630. offset:0,
  1631. tickmarkPlacement:'on'
  1632. }
  1633. // 处理Y轴
  1634. let yAxis={
  1635. ...basicYAxis,
  1636. title: {
  1637. text: '相关性系数',
  1638. textCh: '相关性系数',
  1639. textEn: 'Correlation coefficient',
  1640. align: 'high',
  1641. rotation: 0,
  1642. y: -12,
  1643. textAlign: 'left',
  1644. reserveSpace: false,
  1645. style:{
  1646. ...chartTheme&&chartTheme.yAxisOptions.style
  1647. },
  1648. },
  1649. labels: {
  1650. formatter: function (ctx) {
  1651. let val = ctx.value;
  1652. return val;
  1653. },
  1654. align: 'center',
  1655. style:{
  1656. ...chartTheme&&chartTheme.yAxisOptions.style
  1657. },
  1658. },
  1659. opposite: false,
  1660. tickWidth: 1,
  1661. }
  1662. //处理series
  1663. let seriesData=[]
  1664. this.relevanceChartData.YDataList.forEach((item,index)=>{
  1665. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  1666. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  1667. let serie_item = {
  1668. data: item.Value,
  1669. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || 'spline',
  1670. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  1671. yAxis: 0,
  1672. name: item.Name,
  1673. nameCh: item.Name,
  1674. nameEn: item.NameEn,
  1675. color: item.Color,
  1676. chartType: 'linear',
  1677. lineWidth: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 3,
  1678. marker: {
  1679. enabled: false
  1680. }
  1681. };
  1682. seriesData.push(serie_item)
  1683. })
  1684. const { LeadValue,LeadUnit } = this.relevanceChartData.CorrelationChartInfo;
  1685. const { Source } = this.relevanceChartData.ChartInfo;
  1686. let relevanceUnitEnMap = this.relevanceUnitEnMap;
  1687. let tooltip = {
  1688. formatter: function() {
  1689. let str = `<p>相关性系数:${this.y.toFixed(4)}</p><br><p>领先${ Source===3 ?this.x+'期' : LeadValue+LeadUnit}</p>`
  1690. return str
  1691. },
  1692. formatterCh: function() {
  1693. let str = `<p>相关性系数:${this.y.toFixed(4)}</p><br><p>领先${ Source===3 ?this.x+'期' : LeadValue+LeadUnit}</p>`
  1694. return str
  1695. },
  1696. formatterEn: function() {
  1697. let str = `<p>Correlation coefficient:${this.y.toFixed(4)}</p><br><p>lead${ Source===3 ? this.x+'stage' : LeadValue+relevanceUnitEnMap[LeadUnit]}</p>`
  1698. return str
  1699. }
  1700. }
  1701. this.options = {
  1702. isRelevanceChart: Source===3,
  1703. title: {
  1704. text:''
  1705. },
  1706. series: seriesData,
  1707. yAxis: [yAxis] ,
  1708. xAxis:xAxis,
  1709. tooltip
  1710. }
  1711. console.log('处理结束相关性图表',this.options);
  1712. },
  1713. /* 截面散点图获取详情赋值 */
  1714. initSectionScatterData({ DataResp }) {
  1715. this.chartLimit = {
  1716. min: Number(DataResp.YMinValue),
  1717. max: Number(DataResp.YMaxValue),
  1718. x_min: Number(DataResp.XMinValue),
  1719. x_max: Number(DataResp.XMaxValue)
  1720. }
  1721. this.sectionScatterData = DataResp;
  1722. },
  1723. /* 截面散点图设置 sectionScatterData */
  1724. setSectionScatterChart() {
  1725. this.leftIndex = -1;
  1726. this.rightIndex = -1;
  1727. this.rightTwoIndex = -1;
  1728. const { DataList,XName,XNameEn,YName,YNameEn } = this.sectionScatterData;
  1729. const { min,max,x_min,x_max } = this.chartLimit;
  1730. /* 主题样式*/
  1731. const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
  1732. //y轴
  1733. let yAxis = {
  1734. ...basicYAxis,
  1735. title: {
  1736. text: YName,
  1737. textCh:YName,// 中文
  1738. textEn:YNameEn||YName,
  1739. style:{
  1740. ...chartTheme&&chartTheme.yAxisOptions.style
  1741. },
  1742. align: 'middle',
  1743. },
  1744. labels: {
  1745. style:{
  1746. ...chartTheme&&chartTheme.yAxisOptions.style
  1747. },
  1748. },
  1749. opposite: false,
  1750. reversed: false,
  1751. min: Number(min),
  1752. max: Number(max),
  1753. tickWidth: 1,
  1754. plotBands: this.setAxisPlotAreas(1),
  1755. plotLines: this.setAxisPlotLines(1)
  1756. }
  1757. //x轴
  1758. let xAxis = {
  1759. ...scatterXAxis,
  1760. title: {
  1761. text: XName,
  1762. textCh:XName,// 中文
  1763. textEn:XNameEn || XName,
  1764. style: {
  1765. ...chartTheme&&chartTheme.xAxisOptions.style
  1766. },
  1767. align: 'middle',
  1768. },
  1769. labels: {
  1770. style:{
  1771. ...chartTheme&&chartTheme.xAxisOptions.style
  1772. },
  1773. },
  1774. min: Number(x_min),
  1775. max: Number(x_max),
  1776. plotBands: this.setAxisPlotAreas(3),
  1777. plotLines: this.setAxisPlotLines(3)
  1778. }
  1779. //数据列
  1780. let series = [];
  1781. DataList.forEach((item,index) => {
  1782. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  1783. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  1784. //数据列
  1785. let series_item = {
  1786. data: [],
  1787. type: 'scatter',
  1788. name: item.Name,
  1789. nameCh: item.Name,
  1790. nameEn: item.NameEn||item.Name,
  1791. color: item.Color,
  1792. chartType: 'linear',
  1793. zIndex:1,
  1794. marker: {
  1795. radius: (chartTheme&&chartTheme.lineOptionList[lineIndex].radius)||5,
  1796. },
  1797. }
  1798. item.EdbInfoList.forEach(_ => {
  1799. series_item.data.push({
  1800. x: _.XValue,
  1801. y: _.YValue,
  1802. dataLabels: {
  1803. enabled: _.IsShow,
  1804. allowOverlap: true,
  1805. align: 'left',
  1806. format: _.Name,
  1807. formatCh: _.Name,
  1808. formatEn: _.NameEn||_.Name
  1809. }
  1810. })
  1811. })
  1812. series.push(series_item);
  1813. //趋势线
  1814. if(item.ShowTrendLine) {
  1815. let trend_data = item.TrendLimitData.map((_,_index) => (
  1816. _index === item.TrendLimitData.length-1 ? {
  1817. x: _.X,
  1818. y: _.Y,
  1819. dataLabels: {
  1820. enabled: item.ShowRSquare || item.ShowFitEquation,
  1821. align: 'left',
  1822. color: '#666',
  1823. x: 20,
  1824. y: 30,
  1825. zIndex: 9,
  1826. allowOverlap: true,
  1827. formatter: function(){
  1828. let tag = '';
  1829. item.ShowRSquare && item.ShowFitEquation
  1830. ? tag =`<span>${item.TrendLine}</span><br><span>R²=${item.RSquare}</span>`
  1831. : item.ShowRSquare && !item.ShowFitEquation
  1832. ? tag =`<span>R²=${item.RSquare}</span>`
  1833. : item.ShowFitEquation && !item.ShowRSquare
  1834. ? tag =`<span>${item.TrendLine}</span>`
  1835. : ''
  1836. return tag
  1837. }
  1838. }
  1839. } : {
  1840. x: _.X,
  1841. y: _.Y,
  1842. }
  1843. ))
  1844. let trend_item = {
  1845. data: trend_data,
  1846. type: 'spline',
  1847. linkedTo: ':previous',
  1848. color: item.Color,
  1849. lineWidth: 1,
  1850. chartType: 'linear',
  1851. enableMouseTracking: false,
  1852. dashStyle:'Dash',
  1853. zIndex: 2,
  1854. marker: {
  1855. enabled: false
  1856. }
  1857. }
  1858. series.push(trend_item)
  1859. }
  1860. })
  1861. let tooltip = {
  1862. formatter: function() {
  1863. let series_obj = DataList.find(_ => _.Name === this.series.name);
  1864. let ponit_obj = series_obj.EdbInfoList.find(_ => _.XValue ===this.x && _.YValue===this.y);
  1865. let str=`<b>${ ponit_obj.Name }</b>`;
  1866. str += `<br><span style="color:${this.color}">\u25CF</span>${ponit_obj.XName}: ${this.x} ${ponit_obj.XDate}<br>`;
  1867. str += `<span style="color:${this.color}">\u25CF</span>${ponit_obj.YName}: ${this.y} ${ponit_obj.YDate}`;
  1868. return str
  1869. },
  1870. formatterCh: function() {
  1871. let series_obj = DataList.find(_ => _.Name === this.series.name);
  1872. let ponit_obj = series_obj.EdbInfoList.find(_ => _.XValue ===this.x && _.YValue===this.y);
  1873. let str=`<b>${ ponit_obj.Name }</b>`;
  1874. str += `<br><span style="color:${this.color}">\u25CF</span>${ponit_obj.XName}: ${this.x} ${ponit_obj.XDate}<br>`;
  1875. str += `<span style="color:${this.color}">\u25CF</span>${ponit_obj.YName}: ${this.y} ${ponit_obj.YDate}`;
  1876. return str
  1877. },
  1878. formatterEn: function() {
  1879. let series_obj = DataList.find(_ => _.NameEn === this.series.name);
  1880. let ponit_obj = series_obj.EdbInfoList.find(_ => _.XValue ===this.x && _.YValue===this.y);
  1881. let str=`<b>${ ponit_obj.NameEn }</b>`;
  1882. str += `<br><span style="color:${this.color}">\u25CF</span>${ponit_obj.XNameEn}: ${this.x} ${ponit_obj.XDate}<br>`;
  1883. str += `<span style="color:${this.color}">\u25CF</span>${ponit_obj.YNameEn}: ${this.y} ${ponit_obj.YDate}`;
  1884. return str
  1885. }
  1886. }
  1887. this.options = {
  1888. title: {
  1889. text:''
  1890. },
  1891. series,
  1892. yAxis: [yAxis],
  1893. xAxis,
  1894. tooltip
  1895. }
  1896. this.currentLang=='en' && this.changeOptions()
  1897. },
  1898. // 截面组合图渲染配置
  1899. setSectionalCombinationChart(){
  1900. const {XDataList,UnitList,SeriesList,IsHeap}=this.sectionalCombinationData
  1901. /* 主题样式*/
  1902. const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
  1903. this.leftIndex = SeriesList.findIndex((item) => item.IsAxis===1);
  1904. this.rightIndex = SeriesList.findIndex((item) => !item.IsAxis);
  1905. this.rightTwoIndex = SeriesList.findIndex((item) => item.IsAxis ===2);
  1906. //x轴
  1907. const xAxis={
  1908. categories:XDataList.map(_=>this.currentLang=='en'?_.NameEn:_.Name),
  1909. tickWidth: 1,
  1910. labels: {
  1911. style:{
  1912. ...chartTheme&&chartTheme.xAxisOptions.style
  1913. },
  1914. },
  1915. plotBands: this.setAxisPlotAreas(3),
  1916. plotLines: this.setAxisPlotLines(3)
  1917. }
  1918. let yAxis=[]
  1919. let seriesData=[]
  1920. //有右二轴时排个序 按照左 右 右2的顺序
  1921. const chartData = SeriesList.some(_ =>_.IsAxis===2) ? this.changeEdbOrder(SeriesList) : _.cloneDeep(SeriesList);
  1922. chartData.forEach((item,index)=>{
  1923. //轴位置值相同的下标
  1924. const sameSideIndex = chartData.findIndex(
  1925. (i) => i.IsAxis === item.IsAxis
  1926. );
  1927. const yTitleMap={
  1928. 1:['LeftName','LeftNameEn'],
  1929. 0:['RightName','RightNameEn'],
  1930. 2:['RightTwoName','RightTwoNameEn'],
  1931. }
  1932. let minLimit = 0,maxLimit = 0
  1933. const limitMap = {
  1934. 0:['rightMin','rightMax'],
  1935. 1:['min','max'],
  1936. 2:['rightTwoMin','rightTwoMax']
  1937. }
  1938. if(limitMap[item.IsAxis]){
  1939. minLimit = this.chartLimit[`${limitMap[item.IsAxis][0]}`]||0
  1940. maxLimit = this.chartLimit[`${limitMap[item.IsAxis][1]}`]||0
  1941. }
  1942. let yItem = {
  1943. ...basicYAxis,
  1944. title: {
  1945. text: UnitList[yTitleMap[item.IsAxis][0]],
  1946. textCh:UnitList[yTitleMap[item.IsAxis][0]], // 中文
  1947. // 中文不存在,无论英文有无都显示空
  1948. textEn:UnitList[yTitleMap[item.IsAxis][0]]?UnitList[yTitleMap[item.IsAxis][1]]:'', // 英文
  1949. style:{
  1950. ...chartTheme&&chartTheme.yAxisOptions.style
  1951. },
  1952. align: 'high',
  1953. rotation: 0,
  1954. y: -12,
  1955. // x: (item.IsAxis===0 && this.rightTwoIndex>-1) ? -chartData[this.rightTwoIndex].Unit.length*12 : 0,
  1956. textAlign: item.IsAxis===1 ? 'left' : 'right',
  1957. reserveSpace: false
  1958. },
  1959. labels: {
  1960. formatter: function (ctx) {
  1961. return ctx.value;
  1962. },
  1963. align: 'center',
  1964. x: [0,2].includes(item.IsAxis) ? 5 : -5,
  1965. style: {
  1966. ...chartTheme&&chartTheme.yAxisOptions.style,
  1967. }
  1968. },
  1969. opposite: [0,2].includes(item.IsAxis),
  1970. min: Number(minLimit),
  1971. max: Number(maxLimit),
  1972. tickWidth: 1,
  1973. visible: sameSideIndex === index,
  1974. plotBands: this.setAxisPlotAreas(item.IsAxis),
  1975. plotLines: this.setAxisPlotLines(item.IsAxis)
  1976. };
  1977. //堆叠图的yAxis必须一致 数据列所对应的y轴
  1978. let serie_yIndex = index;
  1979. if(IsHeap==1) {
  1980. // 类型为堆叠图时公用第一个指标y轴
  1981. serie_yIndex = 0;
  1982. }
  1983. //数据列
  1984. let dataArr=item.DataList||[]
  1985. // 根据NoDataEdbIndex 将对应位置的值置为null
  1986. dataArr.forEach((i,index)=>{
  1987. if(item.NoDataEdbIndex.includes(index)){
  1988. dataArr[index]=null
  1989. }
  1990. })
  1991. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  1992. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  1993. let obj={
  1994. data:dataArr,
  1995. type: item.ChartStyle||'',
  1996. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  1997. chartType:'linear',
  1998. yAxis: serie_yIndex,
  1999. name:item.SeriesName,
  2000. nameCh:item.SeriesName,
  2001. nameEn:item.SeriesNameEn,
  2002. unitName:UnitList[yTitleMap[item.IsAxis][0]],
  2003. unitNameCh:UnitList[yTitleMap[item.IsAxis][0]],
  2004. unitNameEn:UnitList[yTitleMap[item.IsAxis][0]]?UnitList[yTitleMap[item.IsAxis][1]]:'',
  2005. color: item.ChartColor,
  2006. lineWidth: Number(item.ChartWidth)||(chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth),
  2007. borderWidth: 1,
  2008. borderColor: item.ChartColor,
  2009. marker: {//展示数据点
  2010. enabled:item.ChartStyle!='column'&&item.IsPoint?true:false,
  2011. radius: (chartTheme&&chartTheme.lineOptionList[lineIndex].radius)||5,
  2012. },
  2013. dataLabels: {//展示数值
  2014. enabled: item.IsNumber?true:false,
  2015. align:item.ChartStyle=='column'?'center':undefined,
  2016. y:item.ChartStyle=='column'?-20:0,
  2017. inside: item.ChartStyle=='column'?false:undefined,
  2018. crop: item.ChartStyle=='column'?false:true,
  2019. },
  2020. stacking:IsHeap==1?'normal':undefined,
  2021. zIndex: ['line','spline'].includes(item.ChartStyle) ? 1 : 0, //防止组合图曲线被遮住
  2022. }
  2023. yAxis.push(yItem)
  2024. seriesData.push(obj)
  2025. })
  2026. const tooltip={
  2027. formatter:function () {
  2028. let str=`<b>${this.points[0].x}</b>`
  2029. this.points.forEach(item=>{
  2030. const sObj=seriesData.find(_=>_.name===item.series.name)
  2031. str=str+`<br><span style="color:${item.color}">\u25CF</span>${sObj.name}:${item.y} ${sObj.unitNameCh}`
  2032. })
  2033. return str
  2034. },
  2035. formatterCh:function () {
  2036. let str=`<b>${this.points[0].x}</b>`
  2037. this.points.forEach(item=>{
  2038. const sObj=seriesData.find(_=>_.name===item.series.name)
  2039. str=str+`<br><span style="color:${item.color}">\u25CF</span>${sObj.nameCh}:${item.y} ${sObj.unitNameCh}`
  2040. })
  2041. return str
  2042. },
  2043. formatterEn:function () {
  2044. let str=`<b>${this.points[0].x}</b>`
  2045. this.points.forEach(item=>{
  2046. const sObj=seriesData.find(_=>_.name===item.series.name)
  2047. str=str+`<br><span style="color:${item.color}">\u25CF</span>${sObj.nameEn}:${item.y} ${sObj.unitNameEn}`
  2048. })
  2049. return str
  2050. },
  2051. shared:true
  2052. }
  2053. this.options = {
  2054. title: {
  2055. text:''
  2056. },
  2057. tooltip,
  2058. series: seriesData,
  2059. yAxis: yAxis,
  2060. xAxis,
  2061. };
  2062. if(this.currentLang=='en') this.changeOptions()
  2063. },
  2064. // 截面组合图初始化
  2065. initSectionalCombinationChart(data){
  2066. const { EdbInfoList,DataResp,ChartInfo } = data;
  2067. this.sectionalCombinationData = DataResp;
  2068. this.chartLimit = {
  2069. min:DataResp.LeftMin, //左轴上下限
  2070. max:DataResp.LeftMax,
  2071. rightMin:DataResp.RightMin,//右轴上下限
  2072. rightMax:DataResp.RightMax,
  2073. rightTwoMin:DataResp.Right2Min,//右二轴上下限
  2074. rightTwoMax:DataResp.Right2Max,
  2075. }
  2076. this.IsHeap=DataResp.IsHeap?true:false
  2077. //默认来源搞一下
  2078. this.setDefaultSourceFrom();
  2079. this.setSectionalCombinationChart()
  2080. },
  2081. // 截面组合图渲染更新
  2082. handleUpdateSectionalCombinationChart(e){
  2083. // console.log(e);
  2084. // console.log(this.sectionalCombinationData);
  2085. if(e.type==='isAxis'){
  2086. e.data.seriesData.forEach(item=>{
  2087. this.sectionalCombinationData.SeriesList.forEach(_item=>{
  2088. if(item.seriesName===_item.SeriesName){
  2089. _item.IsAxis=item.IsAxis
  2090. }
  2091. })
  2092. })
  2093. // 更新上下限
  2094. this.calcYAxislimit(this.sectionalCombinationData.SeriesList)
  2095. }else if(e.type==='chartType'){
  2096. e.data.seriesData.forEach(item=>{
  2097. this.sectionalCombinationData.SeriesList.forEach(_item=>{
  2098. if(item.seriesName===_item.SeriesName){
  2099. _item.ChartStyle=item.seriesChartType
  2100. }
  2101. })
  2102. })
  2103. }else if(e.type==='dataPoint'){
  2104. e.data.seriesData.forEach(item=>{
  2105. this.sectionalCombinationData.SeriesList.forEach(_item=>{
  2106. if(item.seriesName===_item.SeriesName){
  2107. _item.IsPoint=item.showDataPoint?1:0
  2108. }
  2109. })
  2110. })
  2111. }else if(e.type==='dataValue'){
  2112. e.data.seriesData.forEach(item=>{
  2113. this.sectionalCombinationData.SeriesList.forEach(_item=>{
  2114. if(item.seriesName===_item.SeriesName){
  2115. _item.IsNumber=item.showDataValue?1:0
  2116. }
  2117. })
  2118. })
  2119. }else if(e.type==='ChartColor'){
  2120. e.data.seriesData.forEach(item=>{
  2121. this.sectionalCombinationData.SeriesList.forEach(_item=>{
  2122. if(item.seriesName===_item.SeriesName){
  2123. _item.ChartColor=item.ChartColor
  2124. }
  2125. })
  2126. })
  2127. }else if(e.type==='ChartWidth'){
  2128. e.data.seriesData.forEach(item=>{
  2129. this.sectionalCombinationData.SeriesList.forEach(_item=>{
  2130. if(item.seriesName===_item.SeriesName){
  2131. _item.ChartWidth=item.ChartWidth
  2132. }
  2133. })
  2134. })
  2135. }
  2136. this.setSectionalCombinationChart()
  2137. },
  2138. //雷达图数据初始化
  2139. initRadarData(data) {
  2140. const { DataResp,EdbInfoList,ChartInfo } = data;
  2141. this.leftIndex = -1;
  2142. this.rightIndex = -1;
  2143. this.rightTwoIndex = -1;
  2144. this.radarChartData = {
  2145. YDataList: DataResp.YDataList,
  2146. XDataList: EdbInfoList.filter(_ => DataResp.XEdbIdValue.includes(_.EdbInfoId))
  2147. }
  2148. this.chartLimit = {
  2149. min: Number(ChartInfo.LeftMin),
  2150. max: Number(ChartInfo.LeftMax)
  2151. }
  2152. this.setRadarChart();
  2153. },
  2154. /*雷达图绘图*/
  2155. setRadarChart() {
  2156. const { YDataList,XDataList } = this.radarChartData;
  2157. /* 主题样式*/
  2158. const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
  2159. //x轴
  2160. let xAxis = {
  2161. lineWidth: 0,
  2162. tickLength: 0,
  2163. tickmarkPlacement: 'on',
  2164. categories: XDataList.map(_ => _.EdbAliasName||_.EdbName),
  2165. labels: {
  2166. allowOverlap: true,
  2167. autoRotationLimit: 40,
  2168. distance: 20,
  2169. style: {
  2170. ...chartTheme&&chartTheme.xAxisOptions.style
  2171. }
  2172. }
  2173. }
  2174. //y轴
  2175. const { max,min } = this.chartLimit;
  2176. let yAxis = [{
  2177. gridLineInterpolation: 'polygon',
  2178. gridLineWidth: 1,
  2179. lineWidth: 0,
  2180. endOnTick: false,
  2181. startOnTick: false,
  2182. showLastLabel: true,
  2183. // tickAmount:4,
  2184. title: {
  2185. text: this.chartInfo.Unit,
  2186. textCh: this.chartInfo.Unit,
  2187. textEn: this.chartInfo.UnitEn,
  2188. align: 'high',
  2189. rotation: 0,
  2190. y: 5,
  2191. x:10,
  2192. textAlign: 'left',
  2193. reserveSpace: false,
  2194. style:{
  2195. ...chartTheme&&chartTheme.yAxisOptions.style
  2196. },
  2197. },
  2198. labels: {
  2199. allowOverlap: true,
  2200. style:{
  2201. ...chartTheme&&chartTheme.yAxisOptions.style
  2202. }
  2203. },
  2204. min: Number(min),
  2205. max: Number(max),
  2206. }]
  2207. //系列
  2208. let series = [];
  2209. YDataList.forEach((item,index) => {
  2210. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  2211. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  2212. let serie_item = {
  2213. data: item.Value,
  2214. pointPlacement: 'on',
  2215. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || 'line',
  2216. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  2217. yAxis: 0,
  2218. name: item.Name || item.Date,
  2219. nameCh: item.Name || item.Date,
  2220. nameEn: item.Date,
  2221. color: item.Color,
  2222. lineWidth: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth) || 1,
  2223. chartType: 'linear'
  2224. };
  2225. series.push(serie_item)
  2226. })
  2227. this.options = {
  2228. chart: {
  2229. ...defaultOpts.chart,
  2230. ...chartTheme.drawOption,
  2231. spacing: [2,10,2,10],
  2232. polar:true,
  2233. },
  2234. title: {
  2235. text:''
  2236. },
  2237. pane: {
  2238. size: '80%'
  2239. },
  2240. series,
  2241. yAxis,
  2242. xAxis
  2243. }
  2244. this.currentLang=='en' && this.changeOptions();
  2245. },
  2246. /* 统计频率图 */
  2247. setStatisticFrequency() {
  2248. this.leftIndex = -1;
  2249. this.rightIndex = -1;
  2250. this.rightTwoIndex = -1;
  2251. /* 主题样式*/
  2252. const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
  2253. const { DataList,LeftMaxValue,LeftMinValue,RightMaxValue,RightMinValue } = this.statisticFrequencyData;
  2254. if(!DataList) return
  2255. let xAxis = {
  2256. ...scatterXAxis,
  2257. tickWidth: 1,
  2258. labels: {
  2259. style: {
  2260. ...chartTheme&&chartTheme.xAxisOptions.style
  2261. }
  2262. }
  2263. }
  2264. //y和系列
  2265. let yAxis = [],series = [];
  2266. DataList.forEach((item,index) => {
  2267. let y_item = {
  2268. ...basicYAxis,
  2269. title: {
  2270. text: item.Unit,
  2271. textCh:item.Unit,// 中文
  2272. textEn:item.UnitEn||item.Unit,
  2273. align: 'high',
  2274. rotation: 0,
  2275. y: -12,
  2276. reserveSpace: false,
  2277. style:{
  2278. ...chartTheme&&chartTheme.yAxisOptions.style
  2279. },
  2280. },
  2281. labels: {
  2282. style:{
  2283. ...chartTheme&&chartTheme.yAxisOptions.style
  2284. },
  2285. },
  2286. opposite: item.IsAxis===1?false:true,
  2287. min: index===0? Number(LeftMinValue):Number(RightMinValue),
  2288. max: index===0? Number(LeftMaxValue):Number(RightMaxValue),
  2289. tickWidth: 1,
  2290. }
  2291. //图表可配置的线条数就10条,第11条用第1条的配置,索引取下模
  2292. const lineIndex = chartTheme ? index%chartTheme.lineOptionList.length : index
  2293. let series_item = {
  2294. data: item.Value.map(_ =>[_.X,_.Y]),
  2295. dashStyle: (chartTheme&&chartTheme.lineOptionList[lineIndex].dashStyle)||'Solid',
  2296. type: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineType) || 'spline',
  2297. yAxis: index,
  2298. name: item.Name,
  2299. nameCh: item.Name,
  2300. nameEn: item.NameEn||item.Name,
  2301. color: item.Color,
  2302. lineWidth: (chartTheme&&chartTheme.lineOptionList[lineIndex].lineWidth)||3,
  2303. chartType: 'linear',
  2304. zIndex:1
  2305. }
  2306. series.push(series_item);
  2307. yAxis.push(y_item)
  2308. })
  2309. let tooltip = {
  2310. formatter: function() {
  2311. let xList = DataList[0].Value.map(_ =>_.X);
  2312. let step = xList[1]-xList[0];
  2313. let data_interval = `[${this.x},${this.x+step}]`;
  2314. let str=`<b>${ data_interval }</b>`;
  2315. this.points.forEach(item => {
  2316. str += `<br><span style="color:${item.color}">\u25CF</span>${item.series.name}: ${item.y}%<br>`
  2317. })
  2318. return str
  2319. },
  2320. shared: true
  2321. }
  2322. this.options = {
  2323. title: {
  2324. text:''
  2325. },
  2326. tooltip,
  2327. series,
  2328. yAxis,
  2329. xAxis
  2330. }
  2331. this.currentLang=='en' && this.changeOptions()
  2332. },
  2333. /* 跨品种分析 */
  2334. setCrossVarietyChart() {
  2335. this.leftIndex = -1;
  2336. this.rightIndex = -1;
  2337. this.rightTwoIndex = -1;
  2338. /* 主题样式*/
  2339. const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
  2340. const { min,max,x_min,x_max } = this.chartLimit;
  2341. const { DataList,XName,YName,XNameEn,YNameEn } = this.crossVarietyChartData;
  2342. //y轴
  2343. let yAxis = {
  2344. ...basicYAxis,
  2345. title: {
  2346. text: YName,
  2347. textCh:YName,// 中文
  2348. textEn:YNameEn||YName,
  2349. align: 'middle',
  2350. style: {
  2351. ...chartTheme&&chartTheme.xAxisOptions.style
  2352. }
  2353. },
  2354. labels: {
  2355. style: {
  2356. ...chartTheme&&chartTheme.xAxisOptions.style
  2357. }
  2358. },
  2359. opposite: false,
  2360. reversed: false,
  2361. min: Number(min),
  2362. max: Number(max),
  2363. tickWidth: 1,
  2364. }
  2365. // x轴
  2366. let xAxis = {
  2367. ...scatterXAxis,
  2368. title: {
  2369. text: XName,
  2370. textCh:XName,// 中文
  2371. textEn:XNameEn || XName,
  2372. align: 'middle',
  2373. style: {
  2374. ...chartTheme&&chartTheme.xAxisOptions.style
  2375. }
  2376. },
  2377. labels: {
  2378. style: {
  2379. ...chartTheme&&chartTheme.xAxisOptions.style
  2380. }
  2381. },
  2382. min: Number(x_min),
  2383. max: Number(x_max),
  2384. }
  2385. //数据列
  2386. let series = [];
  2387. const tagMap = { //标签对应文字
  2388. 1: '最新',
  2389. 3: 'Fix'
  2390. }
  2391. DataList.forEach(item => {
  2392. //数据列
  2393. let series_item = {
  2394. data: [],
  2395. type: 'scatter',
  2396. name: item.Name,
  2397. nameCh: item.Name,
  2398. nameEn: item.NameEn||item.Name,
  2399. color: item.Color,
  2400. chartType: 'linear',
  2401. zIndex:1
  2402. }
  2403. item.CoordinatePointData.forEach(_ => {
  2404. series_item.data.push({
  2405. x: _.X,
  2406. y: _.Y,
  2407. dataLabels: {
  2408. enabled: _.ShowTips===1,
  2409. allowOverlap: true,
  2410. align: 'left',
  2411. format: tagMap[_.DateType] || `-${_.DaysAgo}D`,
  2412. }
  2413. })
  2414. })
  2415. series.push(series_item);
  2416. })
  2417. let edbInfoList = this.tableData;
  2418. let tooltip = {
  2419. formatter: function() {
  2420. let series_obj = DataList.find(_ => _.Name === this.series.name);
  2421. let ponit_obj = series_obj.CoordinatePointData.find(_ => _.X ===this.x && _.Y===this.y);
  2422. let xEdbInfo = edbInfoList.find(_ => _.EdbInfoId===ponit_obj.XEdbInfoId);
  2423. let yEdbInfo = edbInfoList.find(_ => _.EdbInfoId===ponit_obj.YEdbInfoId);
  2424. let str=`<b>${ this.series.name }</b>`;
  2425. str += `<br><span style="color:${this.color}">\u25CF</span>${xEdbInfo.EdbName}: ${this.x} ${ponit_obj.XDate}<br>`;
  2426. str += `<span style="color:${this.color}">\u25CF</span>${yEdbInfo.EdbName}: ${this.y} ${ponit_obj.YDate}`;
  2427. return str
  2428. },
  2429. formatterCh: function() {
  2430. let series_obj = DataList.find(_ => _.Name === this.series.name);
  2431. let ponit_obj = series_obj.CoordinatePointData.find(_ => _.X ===this.x && _.Y===this.y);
  2432. let xEdbInfo = edbInfoList.find(_ => _.EdbInfoId===ponit_obj.XEdbInfoId);
  2433. let yEdbInfo = edbInfoList.find(_ => _.EdbInfoId===ponit_obj.YEdbInfoId);
  2434. let str=`<b>${ this.series.name }</b>`;
  2435. str += `<br><span style="color:${this.color}">\u25CF</span>${xEdbInfo.EdbName}: ${this.x} ${ponit_obj.XDate}<br>`;
  2436. str += `<span style="color:${this.color}">\u25CF</span>${yEdbInfo.EdbName}: ${this.y} ${ponit_obj.YDate}`;
  2437. return str
  2438. },
  2439. formatterEn: function() {
  2440. let series_obj = DataList.find(_ => _.NameEn === this.series.name);
  2441. let ponit_obj = series_obj.CoordinatePointData.find(_ => _.X ===this.x && _.Y===this.y);
  2442. let xEdbInfo = edbInfoList.find(_ => _.EdbInfoId===ponit_obj.XEdbInfoId);
  2443. let yEdbInfo = edbInfoList.find(_ => _.EdbInfoId===ponit_obj.YEdbInfoId);
  2444. let str=`<b>${ this.series.name }</b>`;
  2445. str += `<br><span style="color:${this.color}">\u25CF</span>${xEdbInfo.EdbNameEn}: ${this.x} ${ponit_obj.XDate}<br>`;
  2446. str += `<span style="color:${this.color}">\u25CF</span>${yEdbInfo.EdbNameEn}: ${this.y} ${ponit_obj.YDate}`;
  2447. return str
  2448. }
  2449. }
  2450. this.options = {
  2451. title: {
  2452. text:''
  2453. },
  2454. series,
  2455. yAxis: [yAxis],
  2456. xAxis,
  2457. tooltip
  2458. }
  2459. this.currentLang=='en' && this.changeRelevanceLang()
  2460. },
  2461. // 区间分析
  2462. initIntervalAnalysisChartData(data){
  2463. //
  2464. console.log('初始化区间分析数据');
  2465. this.intervalAnalysisChartData=data.DataResp
  2466. this.setLimitData(this.tableData)
  2467. this.setIntervalAnalysisChart()
  2468. },
  2469. setIntervalAnalysisChart(){
  2470. console.log('渲染区间分析图表');
  2471. this.setDefaultChart(this.tableData)
  2472. },
  2473. /* 查询范围为1年内 x轴显示为月/日 否则默认年/月 */
  2474. xLabelDealHandle() {
  2475. const end =
  2476. this.year_select === 5
  2477. ? this.select_date[1]
  2478. : this.year_select === 6
  2479. ? new Date()
  2480. : '';
  2481. const year_differ = this.$moment(end).diff(
  2482. this.$moment(this.select_date[0]),
  2483. 'years',
  2484. true
  2485. );
  2486. // console.log(year_differ)
  2487. if ([5, 6].includes(this.year_select) && year_differ <= 1) {
  2488. return true
  2489. } else {
  2490. return false;
  2491. }
  2492. },
  2493. /* 拼接动态的指标名称小标签 */
  2494. concatDynamicTag({ IsAxis,IsOrder,EdbInfoType,LeadValue,LeadUnit },lang='zh') {
  2495. // IsAxis左轴1 右轴0 2右2轴
  2496. //IsOrder正序false 逆序true
  2497. //EdbInfoType是否是领先指标
  2498. // lang ch 中文 en 英文
  2499. const axisLabelMap = lang=='zh'?{
  2500. 0: '右轴',
  2501. 2: '右2轴'
  2502. }:{
  2503. 0: 'RHS',
  2504. 2: '2-RHS'
  2505. }
  2506. const orderLabelMap = lang=='zh'?{
  2507. 1: '逆序'
  2508. }:{
  2509. 1: 'REV'
  2510. }
  2511. const edbInfoMap = lang=='zh'?{
  2512. 0: '领先'
  2513. }:{
  2514. 0: 'Lead'
  2515. }
  2516. //英文领先单位转换
  2517. const leadUnit = lang==='zh' ? LeadUnit : this.leadUnitEnMap[LeadUnit];
  2518. let axis_tag = axisLabelMap[IsAxis] || '';
  2519. //逆序拼接
  2520. let order_tag = orderLabelMap[Number(IsOrder)] ? `${axis_tag ? ',': ''}${orderLabelMap[Number(IsOrder)]}` : ''
  2521. //领先拼接
  2522. let edb_tag = edbInfoMap[EdbInfoType] ? `${(axis_tag||order_tag) ? ',' : '' }${edbInfoMap[EdbInfoType]} ${LeadValue}${leadUnit}` : '';
  2523. return (axis_tag || order_tag || edb_tag) ? `(${axis_tag}${order_tag}${edb_tag})` : ''
  2524. },
  2525. /* 指标顺序调整 IsAxis: 0右轴 1左轴 2右2*/
  2526. changeEdbOrder(data) {
  2527. // 左轴指标
  2528. let left_edbs = data.filter(_ => _.IsAxis===1);
  2529. //右轴指标
  2530. let right_edbs = data.filter(_ => !_.IsAxis);
  2531. // 右2轴指标
  2532. let right_two_edbs = data.filter(_ => _.IsAxis === 2);
  2533. // 按 左 右 右2顺序排列
  2534. return [left_edbs,right_edbs,right_two_edbs].flat(Infinity);
  2535. },
  2536. /* 获取同侧极值 左右极值 */
  2537. getSameSideExtreme(newval) {
  2538. // // 左侧
  2539. let leftArr = newval.filter(item => item.IsAxis === 1);
  2540. let left_extreme_max = leftArr.length ? Math.max(...leftArr.map(item => Number(item.MaxData))) : undefined;
  2541. let left_extreme_min = leftArr.length ? Math.min(...leftArr.map(item => Number(item.MinData))) : undefined;
  2542. // // 右侧
  2543. let rightArr = newval.filter(item => !item.IsAxis);
  2544. let right_extreme_max = rightArr.length ? Math.max(...rightArr.map(item => Number(item.MaxData))) : undefined;
  2545. let right_extreme_min = rightArr.length ? Math.min(...rightArr.map(item => Number(item.MinData))) : undefined;
  2546. this.left_extreme = leftArr.length ? [left_extreme_max,left_extreme_min] : [];
  2547. this.right_extreme = rightArr.length ? [right_extreme_max,right_extreme_min] : [];
  2548. },
  2549. /* 用于复制指标 */
  2550. async copyCode({EdbInfoId, EdbInfoCategoryType}) {
  2551. let params = {
  2552. PageSize: 100000,
  2553. CurrentIndex: 1,
  2554. EdbInfoId: EdbInfoId,
  2555. }
  2556. const res = EdbInfoCategoryType === 1
  2557. ? await preDictEdbInterface.edbDataInfo(params)
  2558. : await dataBaseInterface.targetList(params);
  2559. if (res.Ret !== 200) return
  2560. let arr = res.Data.Item.DataList || [];
  2561. let str = '日期\t 值\n';
  2562. arr.forEach((item) => (str += `${item.DataTime}\t${item.Value}\n`));
  2563. this.$copyText(str).then(
  2564. (res) => {
  2565. this.$message.success(/* '已成功复制!' */this.$t('MsgPrompt.copy_success_msg'));
  2566. },
  2567. (err) => {
  2568. this.$message.error(/* '复制失败!' */this.$t('MsgPrompt.copy_fail_msg'));
  2569. }
  2570. );
  2571. },
  2572. /* 查看数据 跳转指标库展开具体指标 */
  2573. viewTarget({ UniqueCode,EdbInfoId,EdbInfoCategoryType,ClassifyId,EdbType }) {
  2574. let path = EdbInfoCategoryType ? '/predictEdb' : (EdbType===1?'/edbBasicbase':'/database');
  2575. let {href} = this.$router.resolve({path, query: {
  2576. code: UniqueCode,
  2577. id: EdbInfoId,
  2578. classifyId:ClassifyId
  2579. }});
  2580. window.open(href,'_blank');
  2581. },
  2582. /* 领先指标 过滤负数 小数点*/
  2583. filterCode(item) {
  2584. item.LeadValue=item.LeadValue.replace(/[^\.\d]/g,'').replace('.','');
  2585. },
  2586. /* 线条粗细 过滤最小1 */
  2587. filterWidth(item) {
  2588. item.ChartWidth = Number(item.ChartWidth) >= 1 ? Number(item.ChartWidth) : 1;
  2589. },
  2590. /* 图标复制的 blob方法*/
  2591. copyBlobItem(widthNum,heightNum,svg,genre){
  2592. let bas64 = this.svgToBase64(svg)
  2593. const dynamic_condition = {
  2594. bigScreen:{
  2595. x:1.22,
  2596. zoomY:0.8,
  2597. zoomX:0.8,
  2598. },
  2599. smallScreen:{
  2600. x:1,
  2601. zoomY:1,
  2602. zoomX:1,
  2603. }
  2604. }
  2605. const {x,zoomY,zoomX} = dynamic_condition.smallScreen;
  2606. // const {x,zoomY,zoomX} = document.body.clientWidth > 1500 && genre === '微信' ? dynamic_condition.bigScreen : dynamic_condition.smallScreen;
  2607. const canvas = document.createElement("canvas");
  2608. const ctx = canvas.getContext("2d");
  2609. const img = new Image();
  2610. canvas.width = widthNum / x;
  2611. canvas.height = heightNum / x;
  2612. img.crossOrigin = "Anonymous";
  2613. img.src = bas64;
  2614. img.onload = () => {
  2615. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  2616. if(genre === '微信'){
  2617. ctx.fillStyle="#fff";
  2618. ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  2619. }
  2620. ctx.scale(zoomX,zoomY)
  2621. ctx.drawImage(img, 0, 0); // 将canvas转为blob
  2622. if(window.ClipboardItem) {
  2623. canvas.toBlob(async (blob) => {
  2624. const data = [new ClipboardItem({ [blob.type]: blob })];
  2625. await navigator.clipboard.write(data).then(
  2626. () => {
  2627. // this.$message.success('复制成功!')
  2628. this.$message.success(this.$t('MsgPrompt.copy_success_msg'))
  2629. },
  2630. (error) => {
  2631. console.log('复制失败,稍后再试',error);
  2632. // this.$message.warning('复制失败,稍后再试')
  2633. this.$message.warning(this.$t('MsgPrompt.copy_fail_msg'))
  2634. }
  2635. );
  2636. });
  2637. }else {
  2638. // this.$message.warning('当前协议暂不支持,仅支持https协议')
  2639. this.$message.warning(this.$t('MsgPrompt.http_not_support'))
  2640. }
  2641. };
  2642. },
  2643. /* 图标复制的 区分微信 office 来动态的计算*/
  2644. dynamicWidthAndHeight(type, ChartType, ChartName, tableData) {
  2645. //动态计算高度 宽度
  2646. let heightNum = this.sameOptionType.includes(ChartType) ? 352 + parseInt((tableData - 1) / 2) * 20 : 352;
  2647. let widthNum = this.sameOptionType.includes(ChartType) ? parseFloat(heightNum * (591 / 352)) : 591;
  2648. widthNum = type === "微信" ? 1260 : widthNum;
  2649. heightNum = type === "微信" ? 669 : heightNum;
  2650. //动态 标题
  2651. let count = parseInt(widthNum / 21);
  2652. let reg = new RegExp("(.{" + count + "})", "g");
  2653. let newTitle = ''
  2654. if(this.currentLang == 'zh'){
  2655. newTitle = _.cloneDeep(ChartName).replace(/\s/g, "").replace(reg, "$1<br/>");
  2656. }else{
  2657. newTitle = _.cloneDeep(ChartName);
  2658. }
  2659. //动态配置
  2660. let dynamic_copyOptions = {
  2661. legend: {
  2662. labelFormatter: function () {
  2663. let count = Math.floor(widthNum/2/15);//多少字数换行;
  2664. let reg2 = new RegExp("(.{" + count + "})", "g");
  2665. let newName = this.name.replace(/-/g, "—").replace(/\s/g, "").replace(/(/g, "(").replace(/)/g, ")").replace(reg2, "$1<br/>");
  2666. return newName;
  2667. },
  2668. itemWidth: widthNum > 1000 ? 530 : 235,
  2669. itemStyle: {
  2670. fontSize: 10,
  2671. color: this.chartInfo.ChartThemeStyle&&JSON.parse(this.chartInfo.ChartThemeStyle).legendOptions.itemStyle.color,
  2672. textOverflow:undefined
  2673. },
  2674. },
  2675. seasonLegend: {},
  2676. };
  2677. return {
  2678. heightNum,
  2679. widthNum,
  2680. newTitle,
  2681. dynamic_copyOptions,
  2682. };
  2683. },
  2684. /* 控制y轴配置项是否显示 其他类型图|堆叠图第一个显示|组合图第一个堆叠的样式显示 */
  2685. showYOptionsHandle(item,index) {
  2686. let isShowOptions = true;
  2687. // 图表类型不是堆叠或组合 y轴配置显示
  2688. // 堆叠图类型第一个指标的y轴配置显示 其余不显示
  2689. // 组合图类型 组合样式不是堆叠 显示
  2690. //组合图类型 组合样式是堆叠 第一个堆叠的y轴配置显示 其余相同样式堆叠不显示
  2691. if([3,4].includes(this.chartInfo.ChartType) && index !== 0) {
  2692. isShowOptions = false
  2693. } else if(this.chartInfo.ChartType ===6
  2694. && ['areaspline','column'].includes(item.ChartStyle)
  2695. && index !== this.tableData.findIndex(_ => _.ChartStyle === item.ChartStyle)) {
  2696. isShowOptions = false
  2697. }
  2698. return isShowOptions;
  2699. },
  2700. /* 图表另存为 */
  2701. saveChartOtherHandle() {
  2702. this.isShowSaveOther = true;
  2703. },
  2704. /* 预测配置 分区 */
  2705. getPredictParams({LatestDate,MoveLatestDate,PredictChartColor,ChartStyle},chartStyle='') {
  2706. return {
  2707. zoneAxis: 'x',
  2708. zones: [{
  2709. value: new Date(MoveLatestDate||LatestDate).getTime()+1
  2710. }, {
  2711. dashStyle: 'ShortDot',
  2712. color:(ChartStyle==='column' || chartStyle==='column') ? 'transparent' : PredictChartColor
  2713. }]
  2714. }
  2715. },
  2716. /* 季节图预测数据 年份=分割点年份做分割 年份>分割点年份全为预测 */
  2717. getSeasonPredictParams(timestamp) {
  2718. return timestamp
  2719. ? {
  2720. zoneAxis: 'x',
  2721. zones: [{
  2722. value: new Date(timestamp).getTime()+1
  2723. }, {
  2724. dashStyle: 'ShortDot',
  2725. }]
  2726. }
  2727. : {}
  2728. },
  2729. /* 转base64 */
  2730. svgToBase64(svg) {
  2731. const base64img = `data:image/svg+xml;base64,${window.btoa(
  2732. unescape(encodeURI(svg))
  2733. )}`;
  2734. // console.log(base64img)
  2735. return base64img;
  2736. },
  2737. /* 改变上下限时重绘图 依赖于chartLimit的柱 商品价格 散点截面 */
  2738. changeLimit() {
  2739. //source1 eta图库的类型对应
  2740. const typeMap = {
  2741. 1: this.setDefaultChart,
  2742. 2: this.setSeasonChart,
  2743. 3: this.setStackOrCombinChart,
  2744. 4: this.setStackOrCombinChart,
  2745. 5: this.setScatterChart,
  2746. 6: this.setStackOrCombinChart,
  2747. 7: this.setBarChart,
  2748. 10: this.setSectionScatterChart,
  2749. 11: this.setRadarChart,
  2750. 14: this.setSectionalCombinationChart
  2751. }
  2752. //其他source
  2753. const sourceMap = {
  2754. 2: this.setCommodityChart,
  2755. 10: this.setCrossVarietyChart,
  2756. 12:this.setIntervalAnalysisChart
  2757. // 3:
  2758. }
  2759. if(this.chartInfo.Source === 1) {
  2760. if([7,10,11].includes(this.chartInfo.ChartType)){
  2761. typeMap[this.chartInfo.ChartType]()
  2762. }else{
  2763. console.log('1111');
  2764. this.setAddChartDefault&&this.setAddChartDefault();
  2765. typeMap[this.chartInfo.ChartType](this.tableData)
  2766. }
  2767. }else {
  2768. sourceMap[this.chartInfo.Source]();
  2769. }
  2770. },
  2771. // 设置 起始日期 和 最新日期
  2772. setExtremumDate(){
  2773. //过滤、排序 拿到起始日期
  2774. let startDateList = this.tableData.map(it => it.StartDate)
  2775. .filter(Boolean)
  2776. .sort((a,b)=> new Date(a).getTime() - new Date(b).getTime())
  2777. this.earliestDate = startDateList[0]
  2778. //过滤、排序 拿到最新日期
  2779. let endDateList = this.tableData.map(it => it.LatestDate)
  2780. .filter(Boolean)
  2781. .sort((a,b)=> new Date(b).getTime() - new Date(a).getTime())
  2782. this.latestDate = endDateList[0]
  2783. console.log(this.earliestDate,this.latestDate,'this.latestDate');
  2784. },
  2785. /* 处理轴的标识线结构 在指定轴位置上拼接标识线
  2786. 0:右轴 1:左轴 2:右2轴 x轴固定3
  2787. axisType表示x轴类型 处理时间轴的值 datetime/null
  2788. */
  2789. setAxisPlotLines(axis,axisType=null) {
  2790. const { MarkersLines,ChartType } = this.chartInfo;
  2791. if(!MarkersLines) return []
  2792. let markerLines = JSON.parse(MarkersLines);
  2793. let arr = markerLines.filter(_ => _.isShow&&_.axis===axis)
  2794. let plotLines = arr.map(_ => {
  2795. //是否是x时间轴
  2796. let isXDateAxis = axis===3&&axisType==='datetime';
  2797. let markerValue='';
  2798. if(isXDateAxis) {
  2799. //季节图x轴额外拼个年份
  2800. let nowYear = ChartType===2 ? new Date(this.tableData[0].DataList[1].DataList[0].DataTimestamp).getFullYear() : '';
  2801. console.log(nowYear)
  2802. markerValue = ChartType===2
  2803. ? new Date(`${nowYear}-${_.value}`).getTime()
  2804. : new Date(_.value).getTime()
  2805. }else {
  2806. markerValue = Number(_.value)
  2807. }
  2808. return {
  2809. value: markerValue,
  2810. dashStyle: _.dashStyle,
  2811. width: Number(_.lineWidth),
  2812. color: _.color,
  2813. label: {
  2814. text: _.text||'',
  2815. verticalAlign: _.textPosition,
  2816. style: {
  2817. color: _.textColor,
  2818. fontSize: _.textFontSize
  2819. }
  2820. }
  2821. }
  2822. })
  2823. return plotLines
  2824. },
  2825. /* 处理标识区拼接 axisType表示x轴类型处理时间轴的值 datetime/null */
  2826. setAxisPlotAreas(axis,axisType=null) {
  2827. const { MarkersAreas,ChartType } = this.chartInfo;
  2828. if(!MarkersAreas) return []
  2829. let markerAreas = JSON.parse(MarkersAreas);
  2830. let arr = markerAreas.filter(_ => _.isShow&&_.axis===axis)
  2831. let plotBands = arr.map(_ => {
  2832. //是否是x时间轴
  2833. let isXDateAxis = axis===3&&axisType==='datetime';
  2834. let fromMarkerValue='',toMarkerValue='';
  2835. if(isXDateAxis) {
  2836. //季节图x轴额外拼个年份
  2837. let nowYear = ChartType===2 ? new Date(this.tableData[0].DataList[1].DataList
  2838. [0].DataTimestamp).getFullYear() : '';
  2839. fromMarkerValue = ChartType===2
  2840. ? new Date(`${nowYear}-${_.fromValue}`).getTime()
  2841. : new Date(_.fromValue).getTime()
  2842. toMarkerValue = ChartType===2
  2843. ? new Date(`${nowYear}-${_.toValue}`).getTime()
  2844. : new Date(_.toValue).getTime()
  2845. }else {
  2846. fromMarkerValue = Number(_.fromValue);
  2847. toMarkerValue = Number(_.toValue);
  2848. }
  2849. //默认label有些偏移 重新归正下
  2850. let positionMapValue = {
  2851. 'top': 12,
  2852. 'middle': 0,
  2853. 'bottom': -10
  2854. }
  2855. return {
  2856. from: fromMarkerValue,
  2857. to: toMarkerValue,
  2858. color: _.color,
  2859. label: {
  2860. text: _.text||'',
  2861. verticalAlign: _.textPosition,
  2862. style: {
  2863. color: _.textColor,
  2864. fontSize: _.textFontSize
  2865. },
  2866. y: positionMapValue[_.textPosition]
  2867. }
  2868. }
  2869. })
  2870. return plotBands
  2871. },
  2872. /* 历史图表默认显示图表来源 d毛后端不修复只能自己每次详情处理下*/
  2873. setDefaultSourceFrom() {
  2874. if(!this.chartInfo.SourcesFrom) {
  2875. let themeOpt = JSON.parse(this.chartInfo.ChartThemeStyle);
  2876. this.chartInfo.SourcesFrom = JSON.stringify({
  2877. isShow: true,
  2878. text: this.chartInfo.ChartSource,
  2879. color: themeOpt&&themeOpt.markerOptions.style.color,
  2880. fontSize: themeOpt&&themeOpt.markerOptions.style.fontSize
  2881. });
  2882. }
  2883. },
  2884. /* ----自定义上下限相关--- */
  2885. /* 计算y轴上下限 */
  2886. calcYAxislimit(tableData=[]) {
  2887. //散点图单独处理
  2888. if(this.chartInfo.ChartType===5){
  2889. if(tableData[1]){
  2890. this.chartLimit.min = tableData[1].MinData
  2891. this.chartLimit.max = tableData[1].MaxData
  2892. }
  2893. return
  2894. }
  2895. //分组
  2896. const leftData = tableData.filter(i => i.IsAxis === 1).map(i => [Number(i.MinData), Number(i.MaxData)])
  2897. const rightData = tableData.filter(i => !i.IsAxis).map(i => [Number(i.MinData), Number(i.MaxData)])
  2898. const rightTwoData = tableData.filter(i => i.IsAxis === 2).map(i => [Number(i.MinData), Number(i.MaxData)])
  2899. //计算最大最小值
  2900. if (leftData.length) {
  2901. const {
  2902. Max,
  2903. Min
  2904. } = this.calcLimit(leftData.flat())
  2905. this.chartLimit.min=Min
  2906. this.chartLimit.max=Max
  2907. } else {
  2908. this.leftIndex = -1
  2909. this.chartLimit.min=0
  2910. this.chartLimit.max=0
  2911. }
  2912. if (rightData.length) {
  2913. const {
  2914. Max,
  2915. Min
  2916. } = this.calcLimit(rightData.flat())
  2917. this.chartLimit.rightMin = Min
  2918. this.chartLimit.rightMax = Max
  2919. } else {
  2920. this.rightIndex = -1
  2921. this.chartLimit.rightMin = 0
  2922. this.chartLimit.rightMax = 0
  2923. }
  2924. if (rightTwoData.length) {
  2925. const {
  2926. Max,
  2927. Min
  2928. } = this.calcLimit(rightTwoData.flat())
  2929. this.chartLimit.rightTwoMin = Min
  2930. this.chartLimit.rightTwoMax = Max
  2931. } else {
  2932. this.rightTwoIndex = -1
  2933. this.chartLimit.rightTwoMin = 0
  2934. this.chartLimit.rightTwoMax = 0
  2935. }
  2936. //季节性图-右轴为左轴同比,单独处理
  2937. if(this.chartInfo.ChartType===2){
  2938. if(this.chartInfo.SeasonRightConfig&&this.chartInfo.SeasonRightConfig.IsAdd&&this.chartInfo.SeasonRightConfig.IsShow){
  2939. if(this.chartInfo.SeasonRightConfig.IndicatorType===1){
  2940. this.chartLimit.rightMin = this.chartInfo.SeasonRightConfig.EdbInfoList[0].MinData||0
  2941. this.chartLimit.rightMax = this.chartInfo.SeasonRightConfig.EdbInfoList[0].MaxData||0
  2942. }else{
  2943. this.chartLimit.rightMin = this.tableData[1].MinData||0
  2944. this.chartLimit.rightMax = this.tableData[1].MaxData||0
  2945. }
  2946. }
  2947. }
  2948. console.table([{
  2949. 'y轴': '左轴',
  2950. '最大值': this.chartLimit.max,
  2951. '最小值': this.chartLimit.min
  2952. },
  2953. {
  2954. 'y轴': '右轴',
  2955. '最大值': this.chartLimit.rightMax,
  2956. '最小值': this.chartLimit.rightMin
  2957. },
  2958. {
  2959. 'y轴': '右二轴',
  2960. '最大值': this.chartLimit.rightTwoMax,
  2961. '最小值': this.chartLimit.rightTwoMin
  2962. }
  2963. ])
  2964. },
  2965. calcLimit(arr) {
  2966. return {
  2967. Max: Math.max(...arr),
  2968. Min: Math.min(...arr)
  2969. }
  2970. },
  2971. //图表详情-设置图表上下限
  2972. setLimitData(tableData=[]){
  2973. if([7,10,11,14].includes(this.chartInfo.ChartType)) return
  2974. const {
  2975. //左右轴极值字段
  2976. LeftMin=0,LeftMax=0,
  2977. RightMin=0,RightMax=0,
  2978. Right2Min=0,Right2Max=0,
  2979. MinMaxSave
  2980. } = this.chartInfo
  2981. if(MinMaxSave){
  2982. this.chartLimit.min = Number(LeftMin)
  2983. this.chartLimit.max = Number(LeftMax)
  2984. this.chartLimit.rightMin = Number(RightMin)
  2985. this.chartLimit.rightMax = Number(RightMax)
  2986. this.chartLimit.rightTwoMin = Number(Right2Min)
  2987. this.chartLimit.rightTwoMax = Number(Right2Max)
  2988. //若用户修改过,则检测轴的上下限是否为空,若为空,则需要计算对应轴的上下限
  2989. this.checkChartLimit(tableData)
  2990. }else{
  2991. this.calcYAxislimit(tableData)
  2992. }
  2993. },
  2994. checkChartLimit(tableData=[]){
  2995. //散点图单独处理
  2996. if(this.chartInfo.ChartType===5){
  2997. if(tableData[1]){
  2998. const {min,max} = this.chartLimit
  2999. if(Number(min)===0&&Number(max)===0){
  3000. this.chartLimit.min = tableData[1].MinData
  3001. this.chartLimit.max = tableData[1].MaxData
  3002. }
  3003. }
  3004. return
  3005. }
  3006. const {
  3007. min,max,rightMin,rightMax,rightTwoMin,rightTwoMax
  3008. } = this.chartLimit
  3009. //若轴的上下限均为0,则不管用户有没有修改过,都重新赋值
  3010. if(Number(min)===0&&Number(max)===0){
  3011. const leftData = tableData.filter(i=>i.IsAxis===1).map(i=>[Number(i.MinData),Number(i.MaxData)])
  3012. if(leftData.length){
  3013. const {Max,Min} = this.calcLimit(leftData.flat())
  3014. this.chartLimit.min=Min
  3015. this.chartLimit.max=Max
  3016. }
  3017. }
  3018. if(Number(rightMin)===0&&Number(rightMax)===0){
  3019. const rightData = tableData.filter(i => !i.IsAxis).map(i=>[Number(i.MinData),Number(i.MaxData)])
  3020. if(rightData.length){
  3021. const {Max,Min} = this.calcLimit(rightData.flat())
  3022. this.chartLimit.rightMin = Min
  3023. this.chartLimit.rightMax = Max
  3024. }
  3025. }
  3026. if(Number(rightTwoMin)===0&&Number(rightTwoMax)===0){
  3027. const rightTwoData = tableData.filter(i=>i.IsAxis===2).map(i=>[Number(i.MinData),Number(i.MaxData)])
  3028. if(rightTwoData.length){
  3029. const {Max,Min} = this.calcLimit(rightTwoData.flat())
  3030. this.chartLimit.rightTwoMin = Min
  3031. this.chartLimit.rightTwoMax = Max
  3032. }
  3033. }
  3034. },
  3035. // 柱形堆积控制
  3036. handleHeapChange(){
  3037. this.options.series.forEach(item=>{
  3038. item.stacking=this.IsHeap?'normal':undefined
  3039. })
  3040. },
  3041. /*-------------------- */
  3042. }
  3043. }