123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181 |
- /* 图表配置设置 */
- import Highcharts from 'highcharts';
- import { defaultOpts, seasonOptions,getTerminal,browser } from '@/utils/defaultOptions';
- //获取RGBA的透明度
- const parseRgbaColor = (color='rgba(51, 51, 51, 1)') => {
- const arr = color.match(/(\d(\.\d+)?)+/g) || ['','','',1];
- return parseFloat(arr[3]||1)
- }
- // 散点x轴
- const scatterXAxis = {
- tickPosition: 'inside',
- lineColor: '#bfbfbf',
- tickColor: '#bfbfbf',
- tickLength:5,
- ordinal: false,
- type: 'linear'
- }
- // y轴静态配置
- const basicYAxis = {
- tickLength: 5,
- lineWidth: 1,
- lineColor: '#bfbfbf',
- tickColor: '#bfbfbf',
- // offset: 0,
- visible: true,
- gridLineWidth: 0,
- tickPosition: 'inside',
- endOnTick: false,
- startOnTick: false,
- showLastLabel: true,
- tickPixelInterval: 50,
- }
- export default {
- data() {
- return {
- bgList:[
- {image_url:require('@/assets/img/ppt_m/bg3.jpg')},
- {image_url:require('@/assets/img/ppt_m/bg4.jpg')},
- {image_url:require('@/assets/img/ppt_m/bg5.jpg')},
- // {image_url:'https://hzstatic.hzinsights.com/ppt/bg3.jpg'},
- // {image_url:'https://hzstatic.hzinsights.com/ppt/bg4.jpg'},
- // {image_url:'https://hzstatic.hzinsights.com/ppt/bg5.jpg'},
- ],//首页背景
- //领先频度对应英文
- leadUnitEnMap: {
- '年': 'Y',
- '季': 'Q',
- '月': 'M',
- '周': 'W',
- '天': 'D',
- },
- /* 奇怪柱形图 */
- barDateList: [],//柱形图的绘图数据
- barXIdData: [],//柱形图的x轴
- barEdbData: [],//柱形图的表格数据 只用于取值
- chartLimit: {
- min:'', //左轴上下限
- max:'',
- rightMin:'',//右轴上下限
- rightMax:'',
- rightTwoMin:'',//右二轴上下限
- rightTwoMax:'',
- },
- /* 商品价格曲线 */
- commodityChartData: [],
- commodityXData: [],
- commodityEdbList: [],
- /* 时间截面散点图 */
- sectionScatterData: {},
-
- relevanceChartData:null,//相关性图表
- relevanceUnitEnMap:{
- '年': 'Year',
- '季': 'Season',
- '月': 'Month',
- '周': 'Week',
- '天': 'Day',
- },
- /* 统计频率图 */
- statisticFrequencyData: {},
- /* 跨品种分析图 */
- crossVarietyChartData: {},
- /* 雷达图 */
- radarChartData: {}
- }
- },
- methods: {
- /* 设置options 曲线图 季节图*/
- setOptions() {
- // ChartType: 1曲线图 2季节图 3面积 4柱状 5散点 6组合 季节图中公历和农历数据结构不同
- const chartSetMap = {
- 1: this.setDefaultChart,
- 2: this.setSeasonChart,
- 3: this.setStackOrCombinChart,
- 4: this.setStackOrCombinChart,
- 5: this.setScatterChart,
- 6: this.setStackOrCombinChart
- };
- chartSetMap[this.chartInfo.ChartType]&&chartSetMap[this.chartInfo.ChartType]()
- },
- /* 曲线 */
- setDefaultChart() {
- /* 主题样式*/
- const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
- //拼接标题 数据列
- let data = [],
- ydata = [];
- let rightTwoIndex = this.dataList.findIndex((item) => item.IsAxis ===2);
- // const chartData = _.cloneDeep(this.dataList);
- let chartData = this.dataList.some(_ =>_.IsAxis===2) ? this.changeEdbOrder(this.dataList) : _.cloneDeep(this.dataList);
- chartData.forEach((item, index) => {
- //轴位置值相同的下标
- let sameSideIndex = chartData.findIndex(i => i.IsAxis === item.IsAxis);
- //获取对应轴的上下限
- //非ETA图库图表也不设置自定义上下限
- const isETASource = this.chartInfo.Source===1
- let minLimit = 0,maxLimit = 0
- if(isETASource){
- const limitMap = {
- 0:['rightMin','rightMax'],
- 1:['min','max'],
- 2:['rightTwoMin','rightTwoMax']
- }
- if(limitMap[item.IsAxis]){
- minLimit = this.chartLimit[`${limitMap[item.IsAxis][0]}`]||0
- maxLimit = this.chartLimit[`${limitMap[item.IsAxis][1]}`]||0
- }
- }else{
- minLimit = this.dataList[sameSideIndex].MinData
- maxLimit = this.dataList[sameSideIndex].MaxData
- console.log('useDefault',minLimit,maxLimit)
- }
-
- //y轴
- const textZh = item.ConvertUnit||item.Unit
- const textEn = item.ConvertEnUnit||item.UnitEn||item.ConvertUnit||item.Unit
- let yItem = {
- ...basicYAxis,
- title: {
- text: textZh,
- textCh:textZh,//中文单位
- textEn:textZh?textEn:'',//英文单位,但如果无中文单位则不显示
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- align: 'high',
- rotation: 0,
- y: -12,
- x: (item.IsAxis===0 && rightTwoIndex>-1) ? -chartData[rightTwoIndex].Unit.length*12 : 0,
- textAlign: item.IsAxis===1 ? 'left' : 'right',
- reserveSpace: false
- },
- labels: {
- formatter: function (ctx) {
- let val = ctx.value;
- return val;
- },
- align: 'center',
- x: [0,2].includes(item.IsAxis) ? 2 : -2,
- y: 3,
- style: {
- ...chartTheme&&chartTheme.yAxisOptions.style,
- }
- },
- opposite: [0,2].includes(item.IsAxis),
- reversed: item.IsOrder,
- min: Number(minLimit),
- max: Number(maxLimit),
- tickWidth: 1,
- visible: sameSideIndex === index,
- plotBands: this.setAxisPlotAreas(item.IsAxis),
- plotLines: this.setAxisPlotLines(item.IsAxis)
- };
- // //拼接标题 判断相同指标名称拼接来源
- let dynamic_title = item.EdbName;
- let dynamic_arr = chartData.filter(
- (item) => dynamic_title === item.EdbName
- );
- // 拼接配置 IsAxis左轴1 右轴0 IsOrder正序false 逆序true EdbInfoType是否是领先指标
- let dynamic_tag = this.concatDynamicTag(item);
- let dynamic_tag_en = this.concatDynamicTag(item,'en');
- //预测指标配置
- let predict_params = item.EdbInfoCategoryType === 1 ? this.getPredictParams(item) : {};
- //中英文名称
- const nameCh = dynamic_arr.length > 1
- ? `${item.EdbAliasName||item.EdbName}(${item.SourceName})${dynamic_tag}`
- : `${item.EdbAliasName||item.EdbName}${dynamic_tag}`
- const nameEn = item.EdbNameEn?`${item.EdbNameEn}${dynamic_tag_en}`:''
- //数据列
- let obj = {
- data: [],
- type: (chartTheme&&chartTheme.lineOptionList[index].lineType) || 'spline',
- dashStyle: (chartTheme&&chartTheme.lineOptionList[index].dashStyle)||'Solid',
- yAxis: sameSideIndex,
- name:nameCh,
- nameCh:nameCh,
- nameEn:nameEn,
- color: item.ChartColor,
- lineWidth: Number(item.ChartWidth)||(chartTheme&&chartTheme.lineOptionList[index].lineWidth),
- marker: chartTheme && chartTheme.lineOptionList[index].dataMark && chartTheme.lineOptionList[index].dataMark!='none'?{
- enabled:true,
- symbol: chartTheme.lineOptionList[index].markType || 'circle',
- fillColor:chartTheme.lineOptionList[index].markColor,
- radius: chartTheme.lineOptionList[index].markSize
- }:{},
- ...predict_params
- };
- item.DataList = item.DataList || [];
- for (let i of item.DataList) {
- obj.data.push([i.DataTimestamp, i.Value]);
- }
- data.push(obj);
- ydata.push(yItem);
- });
- /* x轴处理 */
- let isLessThanOneYear = this.xTimeDiffer();
- let xAxis = {
- ...defaultOpts.xAxis,
- labels: {
- formatter: function (ctx) {
- return isLessThanOneYear
- ? Highcharts.dateFormat('%m/%d', ctx.value)
- : Highcharts.dateFormat('%y/%m', ctx.value);
- },
- y: 14,
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- },
- plotBands: this.setAxisPlotAreas(3,'datetime'),
- plotLines: this.setAxisPlotLines(3,'datetime')
- }
- this.options = {
- series: data,
- yAxis: ydata,
- xAxis
- };
- //滚动相关性独立tooltip
- if(this.chartInfo.Source === 4) {
- const { LeadValue,LeadUnit } = this.relevanceChartData.CorrelationChartInfo;
- let relevanceUnitEnMap = this.relevanceUnitEnMap;
- this.options.tooltip = {
- formatter: function() {
- let str = `${Highcharts.dateFormat('%Y/%m/%d',this.x)}<br><p>相关性系数:${this.y.toFixed(4)}</p><br><p>领先${LeadValue+LeadUnit}</p>`
- return str
- },
- formatterCh: function() {
- let str = `${Highcharts.dateFormat('%Y/%m/%d',this.x)}<br><p>相关性系数:${this.y.toFixed(4)}</p><br><p>领先${LeadValue+LeadUnit}</p>`
- return str
- },
- formatterEn: function() {
- 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>`
- return str
- }
- }
- }
- },
- /* 堆叠柱 堆叠面积 组合图 */
- setStackOrCombinChart() {
- const chartTypeMap = {
- 3: 'areaspline',
- 4: 'column',
- 6: ''
- };
- let chartStyle = chartTypeMap[this.chartInfo.ChartType];
- /* 主题样式*/
- const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
- //拼接标题 数据列
- let data = [],
- ydata = [];
- let chartData = this.dataList.some(_ =>_.IsAxis===2) ? this.changeEdbOrder(this.dataList) : _.cloneDeep(this.dataList);
- chartData.forEach((item, index) => {
- //轴位置值相同的下标
- let sameSideIndex = chartData.findIndex(i => i.IsAxis === item.IsAxis);
- //堆叠图的yAxis必须一致 数据列所对应的y轴
- let serie_yIndex = index;
- if([3,4].includes(this.chartInfo.ChartType)) {
- // 类型为堆叠图时公用第一个指标y轴
- serie_yIndex = 0;
- } else if(this.chartInfo.ChartType ===6 && ['areaspline','column'].includes(item.ChartStyle)) {
- // 组合图找第一个堆叠柱状或面积的作为公用
- serie_yIndex = chartData.findIndex(i => i.ChartStyle === item.ChartStyle);
- }
- //数据对应的y轴是公用轴则配置也共享
- item.IsAxis = serie_yIndex === index ? item.IsAxis : chartData[serie_yIndex].IsAxis;
- item.IsOrder = serie_yIndex === index ? item.IsOrder : chartData[serie_yIndex].IsOrder;
- let rightTwoIndex = [3,4].includes(this.chartInfo.ChartType)
- ? -1
- : this.dataList.findIndex((item) => item.IsAxis===2);
- //获取对应轴的上下限
- let minLimit = 0,maxLimit = 0
- const limitMap = {
- 0:['rightMin','rightMax'],
- 1:['min','max'],
- 2:['rightTwoMin','rightTwoMax']
- }
- if(limitMap[item.IsAxis]){
- minLimit = this.chartLimit[`${limitMap[item.IsAxis][0]}`]||0
- maxLimit = this.chartLimit[`${limitMap[item.IsAxis][1]}`]||0
- }
- console.log('test堆积',minLimit,maxLimit)
- //y轴
- let yItem = {
- ...basicYAxis,
- title: {
- text:item.ConvertUnit||item.Unit,
- textCh:item.ConvertUnit||item.Unit,//中文单位
- textEn:item.ConvertEnUnit||item.UnitEn||item.ConvertUnit||item.Unit,//英文单位,但如果无中文单位则不显示
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- align: 'high',
- rotation: 0,
- y: -12,
- x: (item.IsAxis===0 && rightTwoIndex>-1) ? -chartData[rightTwoIndex].Unit.length*12 : 0,
- textAlign: item.IsAxis===1 ? 'left' : 'right',
- reserveSpace: false
- },
- labels: {
- formatter: function (ctx) {
- let val = ctx.value;
- return sameSideIndex !== index ? '' : val;
- },
- align: 'center',
- x: [0,2].includes(item.IsAxis) ? 2 : -2,
- y: 3,
- style: {
- ...chartTheme&&chartTheme.yAxisOptions.style
- }
- },
- opposite: [0,2].includes(item.IsAxis),
- reversed: item.IsOrder,
- min: Number(minLimit),
- max: Number(maxLimit),
- tickWidth: sameSideIndex !== index ? 0 : 1,
- visible: serie_yIndex === index && sameSideIndex ===index,
- plotBands: this.setAxisPlotAreas(item.IsAxis),
- plotLines: this.setAxisPlotLines(item.IsAxis)
- };
- // //拼接标题 判断相同指标名称拼接来源
- let dynamic_title = item.EdbName;
- let dynamic_arr = chartData.filter(
- (item) => dynamic_title === item.EdbName
- );
- // 拼接配置 IsAxis左轴1 右轴0 IsOrder正序false 逆序true EdbInfoType是否是领先指标
- let dynamic_tag = this.concatDynamicTag(item);
- let dynamic_tag_en = this.concatDynamicTag(item,'en');
- //预测指标配置
- let predict_params = item.EdbInfoCategoryType === 1 ? this.getPredictParams(item,chartStyle) : {};
-
- //中英文名称
- const nameCh = dynamic_arr.length > 1
- ? `${item.EdbAliasName||item.EdbName}(${item.SourceName})${dynamic_tag}`
- : `${item.EdbAliasName||item.EdbName}${dynamic_tag}`
- const nameEn = item.EdbNameEn?`${item.EdbNameEn}${dynamic_tag_en}`:''
- //数据列
- let obj = {
- data: [],
- type: chartStyle || item.ChartStyle,
- yAxis: serie_yIndex,
- name:nameCh,
- nameCh:nameCh,
- nameEn:nameEn,
- color: item.ChartColor,
- lineWidth: Number(item.ChartWidth),
- // fillColor: (this.chartInfo.ChartType === 3 || (this.chartInfo.ChartType === 6 && item.ChartStyle === 'areaspline')) ? item.ChartColor : undefined,
- borderWidth: 1,
- borderColor: item.ChartColor,
- zIndex: (this.chartInfo.ChartType === 6 && ['line','spline'].includes(item.ChartStyle)) ? 1 : 0, //防止组合图曲线被遮住
- ...predict_params
- };
- item.DataList = item.DataList || [];
- for (let i of item.DataList) {
- obj.data.push([i.DataTimestamp, i.Value]);
- }
- data.push(obj);
- ydata.push(yItem);
- });
- /* x轴处理 */
- let isLessThanOneYear = this.xTimeDiffer();
- let xAxis = {
- ...defaultOpts.xAxis,
- labels: {
- formatter: function (ctx) {
- return isLessThanOneYear
- ? Highcharts.dateFormat('%m/%d', ctx.value)
- : Highcharts.dateFormat('%y/%m', ctx.value);
- },
- y: 14,
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- },
- plotBands: this.setAxisPlotAreas(3,'datetime'),
- plotLines: this.setAxisPlotLines(3,'datetime')
- }
- this.options = {
- series: data,
- yAxis: ydata,
- xAxis
- };
- },
- /* 季节图配置 */
- setSeasonChart() {
- /* 季节性图的图表配置 */
- const chartData = this.dataList[0];
- const {SeasonRightConfig={}} = this.chartInfo
- /* 主题样式*/
- const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
- // 农历数据需要去除第一项 在ETA1.0.5之后,除了这里 农历和公历处理逻辑一样
- const temChartDataList=chartData.DataList||[]
- const chartDataHandle=this.calendar_type === '农历'?
- temChartDataList.filter((item, index) => index > 0):
- temChartDataList
- // 跟颜色对应
- chartTheme.lineOptionList=chartTheme.lineOptionList.reverse().slice(-chartDataHandle.length)
- let seasonYdata = [],
- seasonData = []
- //获取对应轴的上下限
- let minLimit = 0,maxLimit = 0,rightMin=0,rightMax=0
- minLimit = this.chartLimit.min||0
- maxLimit = this.chartLimit.max||0
- //右轴
- if(SeasonRightConfig.IsShow){
- rightMin = this.chartLimit.rightMin||0
- rightMax = this.chartLimit.rightMax||0
- }
- //数据列
- for (let index in chartDataHandle) {
- let j = chartDataHandle[index]
- //预测指标配置
- let predict_params = chartData.EdbInfoCategoryType === 1 ? this.getSeasonPredictParams(j.CuttingDataTimestamp) : {};
- let serie_item = {
- data: [],
- type: (chartTheme&&chartTheme.lineOptionList[index].lineType) || chartData.ChartStyle,
- dashStyle: (chartTheme&&chartTheme.lineOptionList[index].dashStyle)||'Solid',
- yAxis: 0,
- name: j.ChartLegend,
- lineWidth: (chartTheme&&chartTheme.lineOptionList[index].lineWidth) || 1,
- marker: chartTheme && chartTheme.lineOptionList[index].dataMark && chartTheme.lineOptionList[index].dataMark!='none'?{
- enabled:true,
- symbol: chartTheme.lineOptionList[index].markType || 'circle',
- fillColor:chartTheme.lineOptionList[index].markColor,
- radius: chartTheme.lineOptionList[index].markSize
- }:{},
- ...predict_params
- };
- const data_array = _.cloneDeep(j.DataList);
- data_array &&
- data_array.forEach((item) => {
- serie_item.data.push([item.DataTimestamp, item.Value]);
- });
- seasonData.push(serie_item);
- }
- //数据列-同期上下限/均线/标准差
- const {MaxMinLimits={},SamePeriodAverage={},SamePeriodStandardDeviation={}} = this.chartInfo.SeasonAverageConfig||{}
- if(MaxMinLimits.IsShow&&MaxMinLimits.List&&MaxMinLimits.List.length){
- let serieItem = {
- type:'arearange',//上下限是一个范围
- data:[],
- name:MaxMinLimits.Legend||'同期上下限',
- color:MaxMinLimits.Color||'#075EEE',
- fillOpacity:parseRgbaColor(MaxMinLimits.Color||'')>0.75?0.75:parseRgbaColor(MaxMinLimits.Color||'') //透明度最高0.75
- }
- MaxMinLimits.List.forEach(item=>{
- serieItem.data.push([item.DataTimestamp,item.MinValue,item.MaxValue])
- })
- seasonData.push(serieItem)
- }
- if(SamePeriodAverage.IsShow&&SamePeriodAverage.List){
- let serieItem = {
- type:'line',
- data:[],
- lineWidth:SamePeriodAverage.LineWidth,
- dashStyle:SamePeriodAverage.LineType,
- name:SamePeriodAverage.Legend||'同期均值',
- color:SamePeriodAverage.Color||'#075EEE'
- }
- SamePeriodAverage.List.forEach(item=>{
- serieItem.data.push([item.DataTimestamp,item.Value])
- })
- seasonData.push(serieItem)
- }
- if(SamePeriodStandardDeviation.IsShow&&SamePeriodStandardDeviation.List){
- let serieItem = {
- type:'arearange',//标准差也是一个范围
- data:[],
- name:SamePeriodStandardDeviation.Legend||'同期标准差',
- color:SamePeriodStandardDeviation.Color||'#075EEE',
- fillOpacity:parseRgbaColor(SamePeriodStandardDeviation.Color||'')>0.75?0.75:parseRgbaColor(SamePeriodStandardDeviation.Color||'')
- }
- SamePeriodStandardDeviation.List.forEach(item=>{
- serieItem.data.push([item.DataTimestamp,item.MinValue,item.MaxValue])
- })
- seasonData.push(serieItem)
- }
- //数据列-右轴
- if(SeasonRightConfig.IsShow){
- //右轴的设置
- let serieConfig = SeasonRightConfig.Style==='column'?{
- //柱形
- type:'column',
- color:SeasonRightConfig.ChartColor
- }:{
- //标记点
- type:'spline',
- lineWidth:SeasonRightConfig.LineWidth,
- dashStyle:SeasonRightConfig.LineStyle,
- color:SeasonRightConfig.IsConnected?SeasonRightConfig.LineColor:'rgba(255, 255, 255, 0)',//没有连线颜色设置为透明
- marker:{
- enabled:true,
- symbol:SeasonRightConfig.Shape,
- fillColor:SeasonRightConfig.ChartColor,
- radius:SeasonRightConfig.Size
- },
- }
- let serieItem = {
- ...serieConfig,
- name:SeasonRightConfig.Legend||'右轴',
- data:[],
- yAxis:1,
- }
- const DataList = (SeasonRightConfig.IndicatorType===1?SeasonRightConfig.EdbInfoList[0].DataList:this.dataList[1].DataList)||[]
- DataList.forEach(item=>{
- serieItem.data.push([item.DataTimestamp,item.Value])
- })
- seasonData.push(serieItem)
- }
- //y轴
- const textZh = chartData.ConvertUnit||chartData.Unit
- const textEn = chartData.ConvertEnUnit||chartData.UnitEn||chartData.ConvertUnit||chartData.Unit
- seasonYdata = [{
- ...seasonOptions.yAxis,
- labels: {
- formatter: function () {
- let val = this.value;
- return val;
- },
- align: 'center',
- x: -2,
- y: 3,
- style: {
- ...chartTheme&&chartTheme.yAxisOptions.style
- }
- },
- title: {
- text: `${textZh}`,
- textCh:textZh, // 中文
- // 中文不存在,无论英文有无都显示空
- textEn:textZh?textEn:'', // 英文
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- // text: null,
- align: 'high',
- rotation: 0,
- y: -12,
- x: 0,
- textAlign: 'left',
- reserveSpace: false
- },
- max: Number(maxLimit),
- min: Number(minLimit),
- plotBands: this.setAxisPlotAreas(1),
- plotLines: this.setAxisPlotLines(1)
- }];
- //如果有右轴,seasonYdata加上右轴
- if(SeasonRightConfig.IsShow){
- const rightEdb = (SeasonRightConfig.IndicatorType===1?SeasonRightConfig.EdbInfoList[0]:this.dataList[1])||{unit:''}
- //左轴同比:text为空或% 右轴指标:取指标单位
- if(SeasonRightConfig.IndicatorType===1){
- rightEdb.Unit = SeasonRightConfig.NumFormat===1?'%':''
- }else{
- rightEdb.Unit = this.dataList[1]&&(this.dataList[1].ConvertUnit||this.dataList[1].Unit)||''
- }
- seasonYdata.push({
- ...seasonOptions.yAxis,
- opposite: true,//右轴
- labels: {
- formatter: function () {
- let val = this.value;
- return val;
- },
- align: 'center',
- style: {
- ...chartTheme&&chartTheme.yAxisOptions.style
- }
- },
- title: {
- text: rightEdb.Unit||'',
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- align: 'high',
- rotation: 0,
- y: -12,
- x: -rightEdb.Unit.length*12 ,
- textAlign: 'right',
- reserveSpace: false,
- },
- max: Number(rightMax),
- min: Number(rightMin),
- })
- }
- // 季节图x轴显示月/日 周度指标额外处理时间轴显示
- const xAxis = {
- ...defaultOpts.xAxis,
- labels: {
- formatter: function (ctx) {
- return Highcharts.dateFormat('%m/%d', ctx.value);
- },
- y: 14,
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- },
- plotBands: this.setAxisPlotAreas(3,'datetime'),
- plotLines: this.setAxisPlotLines(3,'datetime')
- };
- const tooltip = {
- ...defaultOpts.tooltip,
- dateTimeLabelFormats: {
- // 时间格式化字符
- day: '%m/%d',
- week: '%m/%d',
- month: '%m/%d',
- year: '%m/%d',
- },
- xDateFormat: '%m/%d',
- }
- let colors = chartTheme&&chartTheme.colorsOptions.reverse();
- this.options = {
- colors: colors.slice(-chartDataHandle.length),
- series: seasonData,
- yAxis: seasonYdata,
- xAxis,
- tooltip
- };
- },
- /* 散点图设置 只允许2指标画图第一个指标值为x轴 第二个指标为y轴 */
- setScatterChart() {
- const chartData = _.cloneDeep(this.dataList);
- /* 主题样式*/
- const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
- // 取2个指标中日期相同的数据
- let real_data = [];
- let tmpData_date = {};//用来取点对应的日期
- let data1 = _.cloneDeep(chartData)[0].DataList || [];
- let data2 = _.cloneDeep(chartData)[1].DataList || [];
- data1.forEach(_item => {
- data2.forEach(_item2 => {
- if(_item.DataTimestamp === _item2.DataTimestamp) {
-
- _item.DataTime = _item.DataTime.replace(/-/g,'/');
- //日期
- let itemIndex =_item.Value + "_" +_item2.Value
- if(tmpData_date[itemIndex]) {
- tmpData_date[itemIndex].push(_item.DataTime)
- } else {
- tmpData_date[itemIndex] = [_item.DataTime]
- }
-
- //值
- real_data.push({
- x: _item.Value,
- y: _item2.Value
- })
- }
- })
- })
- real_data.sort((x,y) => x-y);
- //悬浮窗 拼接日期 原始指标名称
- let tooltip = {
- formatter: function() {
- 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>
- ${chartData[0].EdbName}: <span style="font-weight: 600"> ${this.x}</span><br>
- ${chartData[1].EdbName}: <span style="font-weight: 600"> ${this.y}</span>
- `
- },
- // 中文
- formatterCh: function() {
- 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>
- ${chartData[0].EdbName}: <span style="font-weight: 600"> ${this.x}</span><br>
- ${chartData[1].EdbName}: <span style="font-weight: 600"> ${this.y}</span>
- `
- },
- // 英文
- formatterEn: function() {
- let str1 = `${chartData[0].EdbNameEn}`
- let str2 = `${chartData[1].EdbNameEn}`
- 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>
- ${str1}: <span style="font-weight: 600"> ${this.x}</span><br>
- ${str2}: <span style="font-weight: 600"> ${this.y}</span>
- `
- }
- }
- const { IsOrder,ChartColor,MaxData,MinData } = chartData[0];
- //获取对应轴的上下限
- let minLimit = 0,maxLimit = 0
- minLimit = this.chartLimit.min||0
- maxLimit = this.chartLimit.max||0
- //y轴
- const textYZh = chartData[1].ConvertUnit||chartData[1].Unit
- const textYEn = chartData[1].ConvertEnUnit||chartData[1].UnitEn||chartData[1].ConvertUnit||chartData[1].Unit
- let yAxis = [{
- title: {
- text: `${textYZh}`,
- textCh:textYZh,
- textEn:textYZh?textYEn:'',
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- align: 'high',
- rotation: 0,
- y: -12,
- offset: -(12 * chartData[1].Unit.length),
- },
- labels: {
- formatter: function (ctx) {
- return ctx.value;
- },
- x: -2,
- y: 3,
- align: 'center',
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- },
- opposite: false,
- reversed: IsOrder,
- min: Number(minLimit),
- max: Number(maxLimit),
- tickWidth: 1,
- tickLength: 5,
- lineWidth: 1,
- lineColor: '#bfbfbf',
- tickColor: '#bfbfbf',
- offset: 0,
- visible: true,
- gridLineWidth: 0,
- tickPosition: 'inside',
- endOnTick: false,
- startOnTick: false,
- showLastLabel: true,
- tickPixelInterval: 50,
- plotBands: this.setAxisPlotAreas(1),
- plotLines: this.setAxisPlotLines(1)
- }]
- //数据列
- let series = {
- data: [],
- type: 'scatter',
- name: `${this.chartInfo.ChartName}${IsOrder ? '(逆序)' : ''}`,
- nameCh:`${this.chartInfo.ChartName}${IsOrder ? '(逆序)' : ''}`,
- nameEn:this.chartInfo.ChartNameEn?`${this.chartInfo.ChartNameEn}${IsOrder ? '(reverse)' : ''}`:'',
- chartType: 'linear',
- color: ChartColor,
- marker: {
- radius: (chartTheme&&chartTheme.lineOptionList[0].radius)||5,
- },
- }
- real_data.forEach(_ => {
- series.data.push([_.x,_.y])
- })
-
- const textXZh = chartData[0].ConvertUnit||chartData[0].Unit
- const textXEn = chartData[0].ConvertEnUnit||chartData[0].UnitEn||chartData[0].ConvertUnit||chartData[0].Unit
- this.options = {
- title: {
- text:''
- },
- series: [ series ],
- yAxis,
- xAxis: {
- ...scatterXAxis,
- title: {
- text: `${textXZh}`,
- textCh:textXZh,
- textEn:textXZh?textXEn:'',
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- },
- align: 'high',
- rotation: 0,
- x: 0,
- offset: 15,
- },
- labels: {
- y: 14,
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- },
- plotBands: this.setAxisPlotAreas(3),
- plotLines: this.setAxisPlotLines(3)
- },
- tooltip
- }
- },
- /* 奇怪柱状图 和以上逻辑无公用点 依赖数据为单独的数据
- x轴为指标名称的柱形图 以日期作为series
- */
- setBarChart() {
- let seriesData = [];
- const data = _.cloneDeep(this.barDateList);
- /* 主题样式*/
- const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
- //x轴
- let xAxis = {
- ...scatterXAxis,
- categories: this.barXIdData.map(_ => this.barEdbData.find(edb => edb.EdbInfoId===_).EdbAliasName),
- tickWidth: 1,
- labels: {
- y: 14,
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- }
- }
- const { max,min } = this.chartLimit;
- //y轴
- let yAxis = {
- ...basicYAxis,
- title: {
- text: this.chartInfo.Unit,
- textCh: this.chartInfo.Unit,
- textEn: this.chartInfo.UnitEn,
- align: 'high',
- rotation: 0,
- y: -12,
- x:0,
- textAlign: 'left',
- reserveSpace: false,
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- },
- labels: {
- formatter: function (ctx) {
- let val = ctx.value;
- return val;
- },
- x: -2,
- y: 3,
- align: 'center',
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- },
- min: Number(min),
- max: Number(max),
- opposite: false,
- tickWidth: 1,
- plotBands: this.setAxisPlotAreas(1),
- plotLines: this.setAxisPlotLines(1)
- }
- //数据列
- data.forEach(item => {
- let serie_item = {
- data: item.Value,
- type: 'column',
- yAxis: 0,
- name: item.Name || item.Date,
- nameCh: item.Name || item.Date,
- nameEn: item.Date,
- color: item.Color,
- chartType: 'linear'
- };
- seriesData.push(serie_item)
- })
-
- this.options = {
- title: {
- text:'',
- },
- plotOptions: {
- column:{
- stacking: null,
- },
- },
- series: seriesData,
- yAxis: [ yAxis ],
- xAxis
- }
- },
- /* 获取图表详情后赋值柱状图数据 */
- initBarData(data) {
- const { XEdbIdValue,YDataList,EdbInfoList,ChartInfo } = data;
- // let xData = XEdbIdValue.map(_ => EdbInfoList.find(edb => edb.EdbInfoId===_).EdbAliasName)
- this.barDateList = YDataList;
- this.barXIdData = XEdbIdValue;
- this.barEdbData = EdbInfoList;
- this.chartLimit = {
- min: Number(ChartInfo.LeftMin),
- max: Number(ChartInfo.LeftMax)
- }
- this.setBarChart();
- },
- /* 商品价格曲线设置 绘图逻辑同奇怪柱形图*/
- setCommodityChart() {
- let seriesData = [];
- const data = _.cloneDeep(this.commodityChartData);
- /* 主题样式*/
- const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
- //x轴
- let xAxis = {
- ...scatterXAxis,
- categories: this.commodityXData.map(_ =>_.Name),
- tickWidth: 1,
- labels: {
- y: 14,
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- }
- }
- const { max,min } = this.chartLimit;
- //y轴
- let yAxis = {
- ...basicYAxis,
- title: {
- text: this.commodityEdbList[0].Unit,
- textCh: this.commodityEdbList[0].Unit,
- textEn: this.commodityEdbList[0].Unit?(this.commodityEdbList[0].UnitEn||'英文单位'):'',
- align: 'high',
- rotation: 0,
- y: -12,
- textAlign: 'left',
- reserveSpace: false,
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- },
- labels: {
- formatter: function (ctx) {
- let val = ctx.value;
- return val;
- },
- x: -2,
- y: 3,
- align: 'center',
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- },
- min: Number(min),
- max: Number(max),
- opposite: false,
- tickWidth: 1,
- }
- //数据列
- data.forEach((item,index) => {
- //处理首或/尾全是无效数据的以null填充
- let filterData = this.filterInvalidData(item)
- let serie_item = {
- data: filterData,
- type: (chartTheme&&chartTheme.lineOptionList[index].lineType) || 'spline',
- dashStyle: (chartTheme&&chartTheme.lineOptionList[index].dashStyle)||'Solid',
- yAxis: 0,
- name: item.Name,
- nameCh: item.Name,
- nameEn: item.NameEn,
- color: item.Color,
- chartType: 'linear',
- lineWidth: (chartTheme&&chartTheme.lineOptionList[index].lineWidth) || 3,
- marker: {
- enabled: false
- }
- };
- seriesData.push(serie_item)
- })
- //tooltip
- let commodityEdbList = this.commodityEdbList;
- let commodityXData = this.commodityXData;
- let chartInfo = this.chartInfo;
- let tooltip = {
- formatter: function() {
- let str = '';
- this.points.forEach(item => {
- let obj_item = data.find(_ => _.Name === item.series.name);
- let index = commodityXData.findIndex(_ => _.Name === this.x);
- //合约显示
- let haveContract = obj_item.XEdbInfoIdList[index];
-
- if(haveContract) {
- // 利润曲线指标名
- let edb_name = chartInfo.Source === 5
- ? (index === 0 ? obj_item.NameList[index] : `${chartInfo.ProfitName}(${obj_item.NameList[index]})`)
- : commodityEdbList.find(_ => _.EdbInfoId === obj_item.XEdbInfoIdList[index]).EdbName;
- str+=`<b>${ edb_name }</b>`
-
- if(!obj_item.NoDataEdbList.includes(obj_item.XEdbInfoIdList[index])) {
- str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: ${item.y}<br>`
- }else {
- str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: 无<br>`
- }
- }
- })
- return str||'无合约'
- },
- formatterCh: function() {
- let str = '';
- this.points.forEach(item => {
- let obj_item = data.find(_ => _.Name === item.series.name);
- let index = commodityXData.findIndex(_ => _.Name === this.x);
- //合约显示
- let haveContract = obj_item.XEdbInfoIdList[index];
-
- if(haveContract) {
- // 利润曲线指标名
- let edb_name = chartInfo.Source === 5
- ? (index === 0 ? obj_item.NameList[index] : `${chartInfo.ProfitName}(${obj_item.NameList[index]})`)
- : commodityEdbList.find(_ => _.EdbInfoId === obj_item.XEdbInfoIdList[index]).EdbName;
- str+=`<b>${ edb_name }</b>`
- if(!obj_item.NoDataEdbList.includes(obj_item.XEdbInfoIdList[index])) {
- str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: ${item.y}<br>`
- }else {
- str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: 无<br>`
- }
- }
- })
- return str||'无合约'
- },
- formatterEn: function() {
- let str = '';
- this.points.forEach(item => {
- let obj_item = data.find(_ => _.NameEn === item.series.name);
- let index = commodityXData.findIndex(_ => _.NameEn === this.x);
- //合约显示
- let haveContract = obj_item.XEdbInfoIdList[index];
- if(haveContract) {
- // 利润曲线指标名
- let edb_name = chartInfo.Source === 5
- ? (index === 0 ? obj_item.NameList[index] : `${chartInfo.ProfitNameEn}(${obj_item.NameList[index]})`)
- : commodityEdbList.find(_ => _.EdbInfoId === obj_item.XEdbInfoIdList[index]).EdbNameEn;
- str+=`<b>${ edb_name }</b>`
-
- if(!obj_item.NoDataEdbList.includes(obj_item.XEdbInfoIdList[index])) {
- str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: ${item.y}<br>`
- }else {
- str += `<br><span style="color:${item.color}">\u25CF</span>${obj_item.Date}: 无<br>`
- }
- }
- })
- return str||'无合约'
- },
- shared: true
- }
-
- this.options = {
- title: {
- text:''
- },
- series: seriesData,
- yAxis: [ yAxis ],
- xAxis,
- tooltip
- }
- },
-
- /* 处理无效数据为null */
- filterInvalidData(item) {
- //找出第一个有效数据和最后一个有效数据的index index1 index2
- //0到index1全填null index2到最后一个全为null
- let validateArr = item.XEdbInfoIdList.filter(_ =>_&&!item.NoDataEdbList.includes(_));
- let first_index = item.XEdbInfoIdList.findIndex(_ => _ === validateArr[0]);
- let last_index = item.XEdbInfoIdList.findIndex(_ => _ === validateArr[validateArr.length-1]);
- console.log('first_index',first_index)
- console.log('last_index',last_index)
- let arr = item.Value.map((item,index) => {
- if(index < first_index || index > last_index) {
- return null
- }else {
- return item
- }
- })
- return arr;
- },
- /* 商品价格曲线获取详情赋值 */
- initCommodityData(data) {
- const { XDataList,YDataList,EdbInfoList,ChartInfo,DataResp } = data;
- this.commodityEdbList = EdbInfoList;
- this.commodityChartData = ChartInfo.Source===5?DataResp.YDataList:YDataList;
- this.commodityXData = ChartInfo.Source===5?DataResp.XDataList:XDataList;
- this.chartLimit = {
- min: Number(ChartInfo.LeftMin),
- max: Number(ChartInfo.LeftMax)
- }
- this.setCommodityChart()
- },
- /* 相关性图表初始化 */
- initRelevanceChartData(){
- /* 主题样式*/
- const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
-
- // 处理X轴
- let xAxis={
- categories: this.relevanceChartData.XEdbIdValue,
- tickWidth: 1,
- title: {
- text: this.relevanceChartData.ChartInfo.Source===3 ?`期数(${this.relevanceChartData.CorrelationChartInfo.LeadUnit})` : null,
- textCh:this.relevanceChartData.ChartInfo.Source===3 ? `期数(${this.relevanceChartData.CorrelationChartInfo.LeadUnit})`:null,
- textEn:this.relevanceChartData.ChartInfo.Source===3 ? `stage(${this.relevanceUnitEnMap[this.relevanceChartData.CorrelationChartInfo.LeadUnit]})`:null,
- align: 'high',
- rotation: 0,
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- },
- labels: {
- y: 14,
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- },
- tickInterval: 1,
- offset:0,
- tickmarkPlacement:'on'
- }
- // 处理Y轴
- let yAxis={
- ...basicYAxis,
- title: {
- text: '相关性系数',
- textCh: '相关性系数',
- textEn: 'Correlation coefficient',
- align: 'high',
- rotation: 0,
- y: -12,
- textAlign: 'left',
- reserveSpace: false,
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- },
- labels: {
- formatter: function (ctx) {
- let val = ctx.value;
- return val;
- },
- x: -2,
- y: 3,
- align: 'center',
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- },
- opposite: false,
- tickWidth: 1,
- }
- //处理series
- let seriesData=[]
- this.relevanceChartData.YDataList.forEach((item,index)=>{
- let serie_item = {
- data: item.Value,
- type: (chartTheme&&chartTheme.lineOptionList[index].lineType) || 'spline',
- dashStyle: (chartTheme&&chartTheme.lineOptionList[index].dashStyle)||'Solid',
- yAxis: 0,
- name: item.Name,
- nameCh: item.Name,
- nameEn: item.NameEn,
- color: item.Color,
- chartType: 'linear',
- lineWidth: (chartTheme&&chartTheme.lineOptionList[index].lineWidth) || 3,
- marker: {
- enabled: false
- }
- };
- seriesData.push(serie_item)
- })
-
- const { LeadValue,LeadUnit } = this.relevanceChartData.CorrelationChartInfo;
- const { Source } = this.relevanceChartData.ChartInfo;
- let relevanceUnitEnMap = this.relevanceUnitEnMap;
- let tooltip = {
- formatter: function() {
- let str = `<p>相关性系数:${this.y.toFixed(4)}</p><br><p>领先${ Source===3 ?this.x+'期' : LeadValue+LeadUnit}</p>`
- return str
- },
- formatterCh: function() {
- let str = `<p>相关性系数:${this.y.toFixed(4)}</p><br><p>领先${ Source===3 ?this.x+'期' : LeadValue+LeadUnit}</p>`
- return str
- },
- formatterEn: function() {
- let str = `<p>Correlation coefficient:${this.y.toFixed(4)}</p><br><p>lead${ Source===3 ? this.x+'stage' : LeadValue+relevanceUnitEnMap[LeadUnit]}</p>`
- return str
- }
- }
- this.options = {
- isRelevanceChart: Source===3,
- title: {
- text:''
- },
- series: seriesData,
- yAxis: [yAxis] ,
- xAxis:xAxis,
- tooltip
- }
- },
- /* 截面散点图获取详情赋值 */
- initSectionScatterData({ DataResp }) {
- this.chartLimit = {
- min: Number(DataResp.YMinValue),
- max: Number(DataResp.YMaxValue),
- x_min: Number(DataResp.XMinValue),
- x_max: Number(DataResp.XMaxValue)
- }
- this.sectionScatterData = DataResp;
- this.setSectionScatterChart();
- },
- /* 截面散点图设置 sectionScatterData */
- setSectionScatterChart() {
- const { DataList,XName,XNameEn,XUnitName,XUnitNameEn,YName,YNameEn,YUnitName,YUnitNameEn } = this.sectionScatterData;
- const { min,max,x_min,x_max } = this.chartLimit;
- /* 主题样式*/
- const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
- //y轴
- let yAxis = {
- ...basicYAxis,
- title: {
- text: YName,
- textCh:YName,// 中文
- textEn:YNameEn,
- align: 'middle',
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- },
- labels: {
- x: -2,
- y: 3,
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- },
- opposite: false,
- reversed: false,
- min: Number(min),
- max: Number(max),
- tickWidth: 1,
- plotBands: this.setAxisPlotAreas(1),
- plotLines: this.setAxisPlotLines(1)
- }
- //x轴
- let xAxis = {
- ...scatterXAxis,
- title: {
- text: XName,
- textCh:XName,// 中文
- textEn:XNameEn,
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- },
- align: 'middle',
- },
- labels: {
- y: 14,
- style:{
- ...chartTheme&&chartTheme.xAxisOptions.style
- },
- },
- min: Number(x_min),
- max: Number(x_max),
- plotBands: this.setAxisPlotAreas(3),
- plotLines: this.setAxisPlotLines(3)
- }
- //数据列
- let series = [];
- DataList.forEach(item => {
- //数据列
- let series_item = {
- data: [],
- type: 'scatter',
- name: item.Name,
- nameCh: item.Name,
- nameEn: item.NameEn,
- color: item.Color,
- lineWidth: 0,
- chartType: 'linear',
- zIndex:1,
- marker: {
- radius: (chartTheme&&chartTheme.lineOptionList.radius)||5,
- },
- }
- item.EdbInfoList.forEach(_ => {
- series_item.data.push({
- x: _.XValue,
- y: _.YValue,
- dataLabels: {
- enabled: _.IsShow,
- allowOverlap: true,
- align: 'left',
- format: _.Name,
- formatCh: _.Name,
- formatEn: _.NameEn
- }
- })
- })
- series.push(series_item);
- //趋势线
- if(item.ShowTrendLine) {
-
- let trend_data = item.TrendLimitData.map((_,_index) => (
- _index === item.TrendLimitData.length-1 ? {
- x: _.X,
- y: _.Y,
- dataLabels: {
- enabled: item.ShowRSquare || item.ShowFitEquation,
- align: 'left',
- color: '#666',
- x: 20,
- y: 30,
- zIndex: 9,
- allowOverlap: true,
- formatter: function(){
- let tag = '';
- item.ShowRSquare && item.ShowFitEquation
- ? tag =`<span>${item.TrendLine}</span><br><span>R²=${item.RSquare}</span>`
- : item.ShowRSquare && !item.ShowFitEquation
- ? tag =`<span>R²=${item.RSquare}</span>`
- : item.ShowFitEquation && !item.ShowRSquare
- ? tag =`<span>${item.TrendLine}</span>`
- : ''
- return tag
- }
- }
- } : {
- x: _.X,
- y: _.Y,
- }
- ))
- let trend_item = {
- data: trend_data,
- type: 'spline',
- linkedTo: ':previous',
- color: item.Color,
- lineWidth: 1,
- chartType: 'linear',
- enableMouseTracking: false,
- dashStyle:'Dash',
- zIndex: 2,
- marker: {
- enabled: false
- }
- }
- series.push(trend_item)
- }
- })
- let tooltip = {
- formatter: function() {
- let series_obj = DataList.find(_ => _.Name === this.series.name);
- let ponit_obj = series_obj.EdbInfoList.find(_ => _.XValue ===this.x && _.YValue===this.y);
- let str=`<b>${ ponit_obj.Name }</b>`;
- str += `<br><span style="color:${this.color}">\u25CF</span>${ponit_obj.XName}: ${this.x} ${ponit_obj.XDate}<br>`;
- str += `<span style="color:${this.color}">\u25CF</span>${ponit_obj.YName}: ${this.y} ${ponit_obj.YDate}`;
- return str
- },
- formatterCh: function() {
- let series_obj = DataList.find(_ => _.Name === this.series.name);
- let ponit_obj = series_obj.EdbInfoList.find(_ => _.XValue ===this.x && _.YValue===this.y);
- let str=`<b>${ ponit_obj.Name }</b>`;
- str += `<br><span style="color:${this.color}">\u25CF</span>${ponit_obj.XName}: ${this.x} ${ponit_obj.XDate}<br>`;
- str += `<span style="color:${this.color}">\u25CF</span>${ponit_obj.YName}: ${this.y} ${ponit_obj.YDate}`;
- return str
-
- },
- formatterEn: function() {
- let series_obj = DataList.find(_ => _.NameEn === this.series.name);
- let ponit_obj = series_obj.EdbInfoList.find(_ => _.XValue ===this.x && _.YValue===this.y);
- let str=`<b>${ ponit_obj.NameEn }</b>`;
- str += `<br><span style="color:${this.color}">\u25CF</span>${ponit_obj.XNameEn}: ${this.x} ${ponit_obj.XDate}<br>`;
- str += `<span style="color:${this.color}">\u25CF</span>${ponit_obj.YNameEn}: ${this.y} ${ponit_obj.YDate}`;
- return str
- }
- }
-
- this.options = {
- title: {
- text:''
- },
- series,
- yAxis: [yAxis],
- xAxis,
- tooltip
- }
- },
- /* 统计频率图 */
- setStatisticFrequency() {
- /* 主题样式*/
- const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
- const { DataList,LeftMaxValue,LeftMinValue,RightMaxValue,RightMinValue } = this.statisticFrequencyData;
-
- let xAxis = {
- ...scatterXAxis,
- tickWidth: 1,
- labels: {
- y: 14,
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- }
- }
- //y和系列
- let yAxis = [],series = [];
- DataList.forEach((item,index) => {
- let y_item = {
- ...basicYAxis,
- title: {
- text: item.Unit,
- textCh:item.Unit,// 中文
- textEn:item.UnitEn||item.Unit,
- align: 'high',
- rotation: 0,
- y: -12,
- reserveSpace: false,
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- },
- labels: {
- x: 0,
- y: 3,
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- },
- opposite: item.IsAxis===1?false:true,
- min: index===0? Number(LeftMinValue):Number(RightMinValue),
- max: index===0? Number(LeftMaxValue):Number(RightMaxValue),
- tickWidth: 1,
- }
- let series_item = {
- data: item.Value.map(_ =>[_.X,_.Y]),
- dashStyle: (chartTheme&&chartTheme.lineOptionList[index].dashStyle)||'Solid',
- type: (chartTheme&&chartTheme.lineOptionList[index].lineType) || 'spline',
- yAxis: index,
- name: item.Name,
- nameCh: item.Name,
- nameEn: item.NameEn||item.Name,
- color: item.Color,
- lineWidth: (chartTheme&&chartTheme.lineOptionList[index].lineWidth)||3,
- chartType: 'linear',
- zIndex:1
- }
- series.push(series_item);
- yAxis.push(y_item)
- })
- let tooltip = {
- formatter: function() {
- let xList = DataList[0].Value.map(_ =>_.X);
- let step = xList[1]-xList[0];
- let data_interval = `[${this.x},${this.x+step}]`;
- let str=`<b>${ data_interval }</b>`;
- this.points.forEach(item => {
- str += `<br><span style="color:${item.color}">\u25CF</span>${item.series.name}: ${item.y}%<br>`
- })
- return str
- },
- shared: true
- }
- this.options = {
- title: {
- text:''
- },
- tooltip,
- series,
- yAxis,
- xAxis
- }
- },
- /* 跨品种分析 */
- setCrossVarietyChart() {
-
- const { min,max,x_min,x_max } = this.chartLimit;
- const { DataList,XName,YName,XNameEn,YNameEn } = this.crossVarietyChartData;
- /* 主题样式*/
- const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
- //y轴
- let yAxis = {
- ...basicYAxis,
- title: {
- text: YName,
- textCh:YName,// 中文
- textEn:YNameEn||YName,
- align: 'middle',
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- },
- labels: {
- x: -2,
- y: 3,
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- },
- opposite: false,
- reversed: false,
- min: Number(min),
- max: Number(max),
- tickWidth: 1,
- }
- // x轴
- let xAxis = {
- ...scatterXAxis,
- title: {
- text: XName,
- textCh:XName,// 中文
- textEn:XNameEn || XName,
- align: 'middle',
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- },
- labels: {
- y: 14,
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- },
- min: Number(x_min),
- max: Number(x_max),
- }
- //数据列
- let series = [];
- const tagMap = { //标签对应文字
- 1: '最新',
- 3: 'Fix'
- }
- DataList.forEach(item => {
- //数据列
- let series_item = {
- data: [],
- type: 'scatter',
- name: item.Name,
- nameCh: item.Name,
- nameEn: item.NameEn||item.Name,
- color: item.Color,
- chartType: 'linear',
- zIndex:1
- }
- item.CoordinatePointData.forEach(_ => {
- series_item.data.push({
- x: _.X,
- y: _.Y,
- dataLabels: {
- enabled: _.ShowTips===1,
- allowOverlap: true,
- align: 'left',
- format: tagMap[_.DateType] || `-${_.DaysAgo}D`,
- }
- })
- })
- series.push(series_item);
- })
- let edbInfoList = this.dataList;
- let tooltip = {
- formatter: function() {
- let series_obj = DataList.find(_ => _.Name === this.series.name);
- let ponit_obj = series_obj.CoordinatePointData.find(_ => _.X ===this.x && _.Y===this.y);
-
- let xEdbInfo = edbInfoList.find(_ => _.EdbInfoId===ponit_obj.XEdbInfoId);
- let yEdbInfo = edbInfoList.find(_ => _.EdbInfoId===ponit_obj.YEdbInfoId);
- let str=`<b>${ this.series.name }</b>`;
- str += `<br><span style="color:${this.color}">\u25CF</span>${xEdbInfo.EdbName}: ${this.x} ${ponit_obj.XDate}<br>`;
- str += `<span style="color:${this.color}">\u25CF</span>${yEdbInfo.EdbName}: ${this.y} ${ponit_obj.YDate}`;
- return str
- },
- formatterCh: function() {
- let series_obj = DataList.find(_ => _.Name === this.series.name);
- let ponit_obj = series_obj.CoordinatePointData.find(_ => _.X ===this.x && _.Y===this.y);
-
- let xEdbInfo = edbInfoList.find(_ => _.EdbInfoId===ponit_obj.XEdbInfoId);
- let yEdbInfo = edbInfoList.find(_ => _.EdbInfoId===ponit_obj.YEdbInfoId);
- let str=`<b>${ this.series.name }</b>`;
- str += `<br><span style="color:${this.color}">\u25CF</span>${xEdbInfo.EdbName}: ${this.x} ${ponit_obj.XDate}<br>`;
- str += `<span style="color:${this.color}">\u25CF</span>${yEdbInfo.EdbName}: ${this.y} ${ponit_obj.YDate}`;
- return str
-
- },
- formatterEn: function() {
- let series_obj = DataList.find(_ => _.NameEn === this.series.name);
- let ponit_obj = series_obj.CoordinatePointData.find(_ => _.X ===this.x && _.Y===this.y);
-
- let xEdbInfo = edbInfoList.find(_ => _.EdbInfoId===ponit_obj.XEdbInfoId);
- let yEdbInfo = edbInfoList.find(_ => _.EdbInfoId===ponit_obj.YEdbInfoId);
- let str=`<b>${ this.series.name }</b>`;
- str += `<br><span style="color:${this.color}">\u25CF</span>${xEdbInfo.EdbNameEn}: ${this.x} ${ponit_obj.XDate}<br>`;
- str += `<span style="color:${this.color}">\u25CF</span>${yEdbInfo.EdbNameEn}: ${this.y} ${ponit_obj.YDate}`;
- return str
- }
- }
- this.options = {
- title: {
- text:''
- },
- series,
- yAxis: [yAxis],
- xAxis,
- tooltip
- }
- },
- //雷达图数据初始化
- initRadarData(data) {
- const { DataResp,EdbInfoList,ChartInfo } = data;
-
- this.radarChartData = {
- YDataList: DataResp.YDataList,
- XDataList: EdbInfoList.filter(_ => DataResp.XEdbIdValue.includes(_.EdbInfoId))
- }
- this.chartLimit = {
- min: Number(ChartInfo.LeftMin),
- max: Number(ChartInfo.LeftMax)
- }
- this.setRadarChart();
- },
- /*雷达图绘图*/
- setRadarChart() {
- const { YDataList,XDataList } = this.radarChartData;
- /* 主题样式*/
- const chartTheme = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
- //x轴
- let xAxis = {
- lineWidth: 0,
- tickLength: 0,
- tickmarkPlacement: 'on',
- categories: XDataList.map(_ => _.EdbAliasName||_.EdbName),
- labels: {
- allowOverlap: true,
- autoRotationLimit: 40,
- distance: 20,
- style: {
- ...chartTheme&&chartTheme.xAxisOptions.style
- }
- }
- }
- //y轴
- const { max,min } = this.chartLimit;
- let yAxis = [{
- gridLineInterpolation: 'polygon',
- gridLineWidth: 1,
- lineWidth: 0,
- endOnTick: false,
- startOnTick: false,
- showLastLabel: true,
- // tickAmount:4,
- title: {
- text: this.chartInfo.Unit,
- textCh: this.chartInfo.Unit,
- textEn: this.chartInfo.UnitEn,
- align: 'high',
- rotation: 0,
- y: 5,
- x:10,
- textAlign: 'left',
- reserveSpace: false,
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- },
- },
- labels: {
- allowOverlap: true,
- style:{
- ...chartTheme&&chartTheme.yAxisOptions.style
- }
- },
- min: Number(min),
- max: Number(max),
- }]
- //系列
- let series = [];
- YDataList.forEach((item,index) => {
- let serie_item = {
- data: item.Value,
- pointPlacement: 'on',
- type: (chartTheme&&chartTheme.lineOptionList[index].lineType) || 'line',
- dashStyle: (chartTheme&&chartTheme.lineOptionList[index].dashStyle)||'Solid',
- yAxis: 0,
- name: item.Name || item.Date,
- nameCh: item.Name || item.Date,
- nameEn: item.Date,
- color: item.Color,
- lineWidth: (chartTheme&&chartTheme.lineOptionList[index].lineWidth) || 1,
- chartType: 'linear'
- };
- series.push(serie_item)
- })
- this.options = {
- chart: {
- ...defaultOpts.chart,
- ...chartTheme.drawOption,
- spacing: [2,10,2,10],
- polar:true,
- },
- title: {
- text:''
- },
- pane: {
- size: '80%'
- },
- series,
- yAxis,
- xAxis
- }
- },
- /* 查询范围为1年内 x轴显示为月/日 否则默认年/月 */
- xTimeDiffer() {
- const end_date =
- this.chartInfo.DateType === 5
- ? this.chartInfo.EndDate
- : this.chartInfo.DateType === 6
- ? new Date()
- : '';
- //年限差
- const year_differ = this.$moment(end_date).diff(
- this.$moment(this.chartInfo.StartDate),
- 'years',
- true
- );
- // console.log(year_differ)
- if ([5, 6].includes(this.chartInfo.DateType) && year_differ <= 1) {
- return true;
- } else {
- return false;
- }
- },
- /* 拼接动态的指标名称小标签 */
- concatDynamicTag({ IsAxis,IsOrder,EdbInfoType,LeadValue,LeadUnit },lang='zh') {
- // IsAxis左轴1 右轴0 2右2轴
- //IsOrder正序false 逆序true
- //EdbInfoType是否是领先指标
- // lang ch 中文 en 英文
- const axisLabelMap = lang=='zh'?{
- 0: '右轴',
- 2: '右2轴'
- }:{
- 0: 'RHS',
- 2: '2-RHS'
- }
- const orderLabelMap = lang=='zh'?{
- 1: '逆序'
- }:{
- 1: 'REV'
- }
- const edbInfoMap = lang=='zh'?{
- 0: '领先'
- }:{
- 0: 'Lead'
- }
- //英文领先单位转换
- const leadUnit = lang==='zh' ? LeadUnit : this.leadUnitEnMap[LeadUnit];
- let axis_tag = axisLabelMap[IsAxis] || '';
- //逆序拼接
- let order_tag = orderLabelMap[Number(IsOrder)] ? `${axis_tag ? ',': ''}${orderLabelMap[Number(IsOrder)]}` : ''
- //领先拼接
- let edb_tag = edbInfoMap[EdbInfoType] ? `${(axis_tag||order_tag) ? ',' : '' }${edbInfoMap[EdbInfoType]} ${LeadValue}${leadUnit}` : '';
- return (axis_tag || order_tag || edb_tag) ? `(${axis_tag}${order_tag}${edb_tag})` : ''
- },
- /* 指标顺序调整 IsAxis: 0右轴 1左轴 2右2*/
- changeEdbOrder(data) {
- // 左轴指标
- let left_edbs = data.filter(_ => _.IsAxis===1);
- //右轴指标
- let right_edbs = data.filter(_ => !_.IsAxis);
- // 右2轴指标
- let right_two_edbs = data.filter(_ => _.IsAxis === 2);
- // 按 左 右 右2顺序排列
- return [left_edbs,right_edbs,right_two_edbs].flat(Infinity);
- },
-
- /* 获取轴数值的最大长度 通过真实数据推测而已 也不准确 */
- getLabelMaxLen(data) {
- let value_arr = data.map(_ => String(Math.abs(_.Value)));
- let max_len_value = value_arr.reduce((a,b)=> (a.length > b.length ? a : b))
- let num = Number(max_len_value) > 1 ? String(parseInt(Number(max_len_value))) : max_len_value
- return num.length
- },
- /* 预测配置 分区 */
- getPredictParams({LatestDate,MoveLatestDate,PredictChartColor,ChartStyle},chartStyle='') {
- return {
- zoneAxis: 'x',
- zones: [{
- value: new Date(MoveLatestDate||LatestDate).getTime()+1
- }, {
- dashStyle: 'ShortDot',
- color:(ChartStyle==='column' || chartStyle==='column') ? 'transparent' : PredictChartColor
- }],
- }
- },
-
- /* 季节图预测数据 年份=分割点年份做分割 年份>分割点年份全为预测 */
- getSeasonPredictParams(timestamp) {
- return timestamp
- ? {
- zoneAxis: 'x',
- zones: [{
- value: new Date(timestamp).getTime()+1,
- }, {
- dashStyle: 'ShortDot',
- }]
- }
- : {}
- },
- /* 处理轴的标识线结构 在指定轴位置上拼接标识线
- 0:右轴 1:左轴 2:右2轴 x轴固定3
- axisType表示x轴类型 处理时间轴的值 datetime/null
- */
- setAxisPlotLines(axis,axisType=null) {
- const { MarkersLines,ChartType } = this.chartInfo;
- if(!MarkersLines) return []
-
- let markerLines = JSON.parse(MarkersLines);
- let arr = markerLines.filter(_ => _.isShow&&_.axis===axis)
- let plotLines = arr.map(_ => {
- //是否是x时间轴
- let isXDateAxis = axis===3&&axisType==='datetime';
- let markerValue='';
- if(isXDateAxis) {
- //季节图x轴额外拼个年份
- let nowYear = ChartType===2 ? new Date(this.dataList[0].DataList[1].DataList
- [0].DataTimestamp).getFullYear() : '';
- markerValue = ChartType===2
- ? new Date(`${nowYear}-${_.value}`).getTime()
- : new Date(_.value).getTime()
- }else {
- markerValue = Number(_.value)
- }
- return {
- value: markerValue,
- dashStyle: _.dashStyle,
- width: Number(_.lineWidth),
- color: _.color,
- label: {
- text: _.text||'',
- verticalAlign: _.textPosition,
- style: {
- color: _.textColor,
- fontSize: _.textFontSize
- }
- }
- }
- })
- return plotLines
- },
- /* 处理标识区拼接 axisType表示x轴类型处理时间轴的值 datetime/null */
- setAxisPlotAreas(axis,axisType=null) {
- const { MarkersAreas,ChartType } = this.chartInfo;
- if(!MarkersAreas) return []
- let markerAreas = JSON.parse(MarkersAreas);
- let arr = markerAreas.filter(_ => _.isShow&&_.axis===axis)
- let plotBands = arr.map(_ => {
- //是否是x时间轴
- let isXDateAxis = axis===3&&axisType==='datetime';
- let fromMarkerValue='',toMarkerValue='';
- if(isXDateAxis) {
- //季节图x轴额外拼个年份
- let nowYear = ChartType===2 ? new Date(this.dataList[0].DataList[1].DataList
- [0].DataTimestamp).getFullYear() : '';
- fromMarkerValue = ChartType===2
- ? new Date(`${nowYear}-${_.fromValue}`).getTime()
- : new Date(_.fromValue).getTime()
- toMarkerValue = ChartType===2
- ? new Date(`${nowYear}-${_.toValue}`).getTime()
- : new Date(_.toValue).getTime()
- }else {
- fromMarkerValue = Number(_.fromValue);
- toMarkerValue = Number(_.toValue);
- }
- //默认label有些偏移 重新归正下
- let positionMapValue = {
- 'top': 12,
- 'middle': 0,
- 'bottom': -10
- }
- return {
- from: fromMarkerValue,
- to: toMarkerValue,
- color: _.color,
- label: {
- text: _.text||'',
- verticalAlign: _.textPosition,
- style: {
- color: _.textColor,
- fontSize: _.textFontSize
- },
- y: positionMapValue[_.textPosition]
- }
- }
- })
- return plotBands
- },
- /* ----自定义上下限相关--- */
- setLimitData(tableData=[]){
- const {
- //左右轴极值字段
- LeftMin=0,LeftMax=0,
- RightMin=0,RightMax=0,
- Right2Min=0,Right2Max=0,
- MinMaxSave
- } = this.chartInfo
- if(MinMaxSave){
- this.chartLimit.min = Number(LeftMin)
- this.chartLimit.max = Number(LeftMax)
- this.chartLimit.rightMin = Number(RightMin)
- this.chartLimit.rightMax = Number(RightMax)
- this.chartLimit.rightTwoMin = Number(Right2Min)
- this.chartLimit.rightTwoMax = Number(Right2Max)
- //若用户修改过,则检测轴的上下限是否为空,若为空,则需要计算对应轴的上下限
- this.checkChartLimit(tableData)
- }else{
- this.calcYAxislimit(tableData)
- }
- },
- checkChartLimit(tableData=[]){
- //散点图单独处理
- if(this.chartInfo.ChartType===5){
- if(tableData[1]){
- const {min,max} = this.chartLimit
- if(Number(min)===0&&Number(max)===0){
- this.chartLimit.min = tableData[1].MinData
- this.chartLimit.max = tableData[1].MaxData
- }
- }
- return
- }
- const {
- min,max,rightMin,rightMax,rightTwoMin,rightTwoMax
- } = this.chartLimit
- //若轴的上下限均为0,则不管用户有没有修改过,都重新赋值
- if(Number(min)===0&&Number(max)===0){
- const leftData = tableData.filter(i=>i.IsAxis===1).map(i=>[Number(i.MinData),Number(i.MaxData)])
- if(leftData.length){
- const {Max,Min} = this.calcLimit(leftData.flat())
- this.chartLimit.min=Min
- this.chartLimit.max=Max
- }
- }
- if(Number(rightMin)===0&&Number(rightMax)===0){
- const rightData = tableData.filter(i => !i.IsAxis).map(i=>[Number(i.MinData),Number(i.MaxData)])
- if(rightData.length){
- const {Max,Min} = this.calcLimit(rightData.flat())
- this.chartLimit.rightMin = Min
- this.chartLimit.rightMax = Max
- }
- }
- if(Number(rightTwoMin)===0&&Number(rightTwoMax)===0){
- const rightTwoData = tableData.filter(i=>i.IsAxis===2).map(i=>[Number(i.MinData),Number(i.MaxData)])
- if(rightTwoData.length){
- const {Max,Min} = this.calcLimit(rightTwoData.flat())
- this.chartLimit.rightTwoMin = Min
- this.chartLimit.rightTwoMax = Max
- }
- }
- },
- /* 计算y轴上下限 */
- calcYAxislimit(tableData=[]) {
- //散点图单独处理
- if(this.chartInfo.ChartType===5){
- if(tableData[1]){
- this.chartLimit.min = tableData[1].MinData
- this.chartLimit.max = tableData[1].MaxData
- }
- return
- }
- //分组
- const leftData = tableData.filter(i => i.IsAxis === 1).map(i => [Number(i.MinData), Number(i.MaxData)])
- const rightData = tableData.filter(i => !i.IsAxis).map(i => [Number(i.MinData), Number(i.MaxData)])
- const rightTwoData = tableData.filter(i => i.IsAxis === 2).map(i => [Number(i.MinData), Number(i.MaxData)])
- //计算最大最小值
- if (leftData.length) {
- const {
- Max,
- Min
- } = this.calcLimit(leftData.flat())
- this.chartLimit.min=Min
- this.chartLimit.max=Max
- } else {
- this.leftIndex = -1
- this.chartLimit.min=0
- this.chartLimit.max=0
- }
- if (rightData.length) {
- const {
- Max,
- Min
- } = this.calcLimit(rightData.flat())
- this.chartLimit.rightMin = Min
- this.chartLimit.rightMax = Max
- } else {
- this.rightIndex = -1
- this.chartLimit.rightMin = 0
- this.chartLimit.rightMax = 0
- }
- if (rightTwoData.length) {
- const {
- Max,
- Min
- } = this.calcLimit(rightTwoData.flat())
- this.chartLimit.rightTwoMin = Min
- this.chartLimit.rightTwoMax = Max
- } else {
- this.rightTwoIndex = -1
- this.chartLimit.rightTwoMin = 0
- this.chartLimit.rightTwoMax = 0
- }
- //季节性图-右轴为左轴同比,单独处理
- if(this.chartInfo.ChartType===2){
- if(this.chartInfo.SeasonRightConfig&&this.chartInfo.SeasonRightConfig.IsShow){
- if(this.chartInfo.SeasonRightConfig.IndicatorType===1){
- this.chartLimit.rightMin = this.chartInfo.SeasonRightConfig.EdbInfoList[0].MinData||0
- this.chartLimit.rightMax = this.chartInfo.SeasonRightConfig.EdbInfoList[0].MaxData||0
- }else{
- this.chartLimit.rightMin = tableData[1].MinData||0
- this.chartLimit.rightMax = tableData[1].MaxData||0
- }
-
- }
- }
- },
- calcLimit(arr) {
- return {
- Max: Math.max(...arr),
- Min: Math.min(...arr)
- }
- },
- /*-------------------- */
- },
- };
|