chartPublic.js 115 KB

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