Commit 2beb13a6 authored by 陈龙's avatar 陈龙

feat: 优化图表代码

parent 0c33a949
...@@ -319,6 +319,7 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth ...@@ -319,6 +319,7 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth
top: needUnit ? 80 : 60, top: needUnit ? 80 : 60,
left: 10 + leftNum * axisWidth, left: 10 + leftNum * axisWidth,
right: rightNum === 0 ? 20 : rightNum * axisWidth, right: rightNum === 0 ? 20 : rightNum * axisWidth,
bottom: 60
}; };
const headTemplate = (param) => { const headTemplate = (param) => {
if (!param) return ''; if (!param) return '';
...@@ -465,18 +466,19 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth ...@@ -465,18 +466,19 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth
if (!justLine && chartType) { if (!justLine && chartType) {
if (chartType === 'boxChart') { if (chartType === 'boxChart') {
const otherData = dataSource?.[0]?.dataModel.map(item => { const otherData = dataSource?.[0]?.dataModel.map(item => {
const {firstPV, lastPV, maxPV, minPV} = item; const {firstPV, lastPV, maxPV, minPV, pt} = item;
return [firstPV, lastPV, minPV, maxPV] return [moment(pt).valueOf(), firstPV, lastPV, minPV, maxPV]
}) || []; //当存在othersData的时候,只是单曲线 }) || []; //当存在othersData的时候,只是单曲线
xAxis = {type: 'category', data: series[0].data.map(item => moment(item[0]).format('YYYY-MM-DD HH:mm:ss'))}; // xAxis = {type: 'category', data: series[0].data.map(item => moment(item[0]).format('YYYY-MM-DD HH:mm:ss'))};
xAxis = {type: 'time'};
decorateAxisGridLine(xAxis, showGridLine); decorateAxisGridLine(xAxis, showGridLine);
let unit = '' let unit = ''
series = series.map(item => { series = series.map(item => {
if (item.unit) unit = item.unit; if (item.unit) unit = item.unit;
let _item = {...item, symbol: 'none'}; let _item = {...item, symbol: 'none'};
_item.data = _item?.data?.map(d => { /* _item.data = _item?.data?.map(d => {
return d[1] || null return d[1] || null
}) || []; }) || [];*/
return _item; return _item;
}) })
series.push({ series.push({
...@@ -495,18 +497,21 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth ...@@ -495,18 +497,21 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth
} else { } else {
let _maxData = []; let _maxData = [];
let _minData = []; let _minData = [];
const formatStr = contrastOption === 'day' ? '2020-01-01 HH:mm:00' : '2020-01-DD HH:mm:00';// 用来做同期对比,把日期拉到同一区间
dataSource?.[0]?.dataModel.forEach(item => { dataSource?.[0]?.dataModel.forEach(item => {
const {firstPV, lastPV, maxPV, minPV} = item; const {firstPV, lastPV, maxPV, minPV, pt} = item;
_maxData.push(maxPV); let time = contrast ? moment(pt).format(formatStr) : pt;
_minData.push(minPV); _maxData.push([moment(time).valueOf(), maxPV - minPV]);
_minData.push([moment(time).valueOf(), minPV]);
}); //当存在othersData的时候,只是单曲线 }); //当存在othersData的时候,只是单曲线
xAxis = {type: 'category', data: series[0].data.map(item => moment(item[0]).format('YYYY-MM-DD HH:mm:ss'))}; // xAxis = {type: 'category', data: series[0].data.map(item => moment(item[0]).format('YYYY-MM-DD HH:mm:ss'))};
xAxis = {type: 'time'};
decorateAxisGridLine(xAxis, showGridLine); decorateAxisGridLine(xAxis, showGridLine);
series = series.map(item => { series = series.map(item => {
let _item = {...item, symbol: 'none'}; let _item = {...item, symbol: 'none'};
_item.data = _item?.data?.map(d => { /* _item.data = _item?.data?.map(d => {
return d[1] || null return d[1] || null
}) || []; }) || [];*/
return _item; return _item;
}); });
console.log(series); console.log(series);
...@@ -530,6 +535,15 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth ...@@ -530,6 +535,15 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth
}) })
} }
} }
restOption.dataZoom = [
{
show: true,
bottom: 10,
start: 0,
end: 100,
height: 28
}
];
return { return {
yAxis, yAxis,
grid, grid,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment