|
|
@ -1,7 +1,8 @@ |
|
|
|
/* eslint-disable max-len,object-curly-newline */ |
|
|
|
import dayjs from 'dayjs'; |
|
|
|
import max from 'lodash/max'; |
|
|
|
import { colors, defaultSelectedLegend, generateDefaultSeries, legendData, yAxisData } from '@/config/chart'; |
|
|
|
import isNaN from 'lodash/isNaN'; |
|
|
|
import { colors, generateDefaultSeries, legendData, yAxisData } from '@/config/chart'; |
|
|
|
|
|
|
|
/** |
|
|
|
* 生成chart所需参数 |
|
|
@ -33,15 +34,15 @@ function generateParams(data) { |
|
|
|
}; |
|
|
|
data.forEach(item => { |
|
|
|
result.time.push(dayjs(new Date(+item.time)).format('YY/MM/DD HH:mm')); |
|
|
|
result.so2.push(+item.so2); |
|
|
|
result.saltR.push(+item.saltR); |
|
|
|
result.saltT.push(+item.saltT); |
|
|
|
result.environmentTemperature.push(+item.environmentTemperature); |
|
|
|
result.environmentHumidity.push(+item.environmentHumidity); |
|
|
|
result.corrosionXIN.push(+item.corrosion1); |
|
|
|
result.corrosionTONG.push(+item.corrosion2); |
|
|
|
result.corrosionLV.push(+item.corrosion3); |
|
|
|
result.corrosionGANG.push(+item.corrosion4); |
|
|
|
!isNaN(+item.so2) && result.so2.push(+item.so2); |
|
|
|
!isNaN(+item.saltR) && result.saltR.push(+item.saltR); |
|
|
|
!isNaN(+item.saltT) && result.saltT.push(+item.saltT); |
|
|
|
!isNaN(+item.environmentTemperature) && result.environmentTemperature.push(+item.environmentTemperature); |
|
|
|
!isNaN(+item.environmentHumidity) && result.environmentHumidity.push(+item.environmentHumidity); |
|
|
|
!isNaN(+item.corrosion1) && result.corrosionXIN.push(+item.corrosion1); |
|
|
|
!isNaN(+item.corrosion2) && result.corrosionTONG.push(+item.corrosion2); |
|
|
|
!isNaN(+item.corrosion3) && result.corrosionLV.push(+item.corrosion3); |
|
|
|
!isNaN(+item.corrosion4) && result.corrosionGANG.push(+item.corrosion4); |
|
|
|
}); |
|
|
|
return result; |
|
|
|
} |
|
|
@ -138,11 +139,10 @@ function generateGrid(yAxis) { |
|
|
|
/** |
|
|
|
* 生成chart参数 |
|
|
|
* @param {Object[]} rawData 返回段返回的data数据 |
|
|
|
* @param {Object[]} yAxis |
|
|
|
* @returns {{yAxis: [{axisLabel: {formatter: string}, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string},{axisLabel: {formatter: string}, offset: number, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string},{axisLabel: {formatter: string}, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string},{axisLabel: {formatter: string}, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string},{axisLabel: {formatter: string}, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string},null,null,null], xAxis: [{data: *[], axisTick: {alignWithLabel: boolean}, type: string}], color: string[], grid: {right: string}, legend: {data: string[]}, series: [{data: *[], name: string, type: string},{data: *[], name: string, type: string, yAxisIndex: number},{data: *[], name: string, type: string, yAxisIndex: number},{data: *[], name: string, type: string, yAxisIndex: number},{data: *[], name: string, type: string, yAxisIndex: number},null,null,null], tooltip: {axisPointer: {type: string}, trigger: string}, toolbox: {feature: {saveAsImage: {show: boolean}, restore: {show: boolean}, dataView: {show: boolean, readOnly: boolean}}}}} |
|
|
|
* @param {Object} selected 选中的legend |
|
|
|
* @returns {{yAxis: ({axisLabel: {formatter: string}, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string}|{axisLabel: {formatter: string}, offset: number, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string})[], xAxis: [{data: *[], axisTick: {alignWithLabel: boolean}, type: string}], color: [string,string,string,string,string,string,string,string,string], grid: {left: number, right: number}, legend: {data: [string,string,string,string,string,string,string,string,string], type: string, selected}, series: (({data: ([]|number|string|*), name: string, type: string}|{data: ([]|number|BufferSource|string|*), name: string, type: string, yAxisIndex: number}|{data: ([]|string|*), name: string, type: string, yAxisIndex: number}|{data: [], name: string, type: string, yAxisIndex: number})[]|*[]), tooltip: {axisPointer: {type: string, snap: boolean}, trigger: string}, dataZoom: [{type: string},{type: string}]}} |
|
|
|
*/ |
|
|
|
// eslint-disable-next-line import/prefer-default-export
|
|
|
|
export function generateChartOption(rawData, selected = defaultSelectedLegend) { |
|
|
|
export function generateChartOption(rawData, selected) { |
|
|
|
const data = generateParams(rawData); |
|
|
|
const yAxis = generateYAxis(selected); |
|
|
|
const series = generateSeries(data, yAxis); |
|
|
|