From e912987f60335ffe5ed2dbb7dd0b52f8fc3a3e99 Mon Sep 17 00:00:00 2001 From: zhangyu Date: Wed, 23 Aug 2023 14:20:42 +0800 Subject: [PATCH] =?UTF-8?q?NEZ-3121=20fix=EF=BC=9Adashboard=20chart=20time?= =?UTF-8?q?series=20Y=20=E8=BD=B4=E5=88=BB=E5=BA=A6=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chart/chart/chartTimeSeries.vue | 30 ++++++++++++++++--- .../src/components/chart/chartDataFormat.js | 10 +++++++ .../src/components/chart/chartMixin.js | 4 +++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue b/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue index f9a323bc2..1386d9f54 100644 --- a/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue +++ b/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue @@ -169,18 +169,40 @@ export default { delete chartOption.tooltip.position } // 左y轴 - chartOption.yAxis[0].axisLabel.formatter = this.yAxisLabelFormatter(minValue, maxValue, copies, unit, decimals) - + const leftData = this.chartData.filter(item => !item[0].yAxisIndex) + console.log(leftData) + const leftInfo = this.getMinMaxFromData(leftData, this.chartInfo.unit) // + chartOption.yAxis[0].minInterval = chartDataFormat.Interval(leftInfo.maxValue, leftInfo.copies, leftInfo.unit.type, 'min') + chartOption.yAxis[0].maxInterval = chartDataFormat.Interval(leftInfo.maxValue, leftInfo.copies, leftInfo.unit.type, 'max') * Math.ceil(chartOption.series.length / 5) + if (this.chartInfo.param.stack) { + chartOption.yAxis[0].maxInterval = chartOption.yAxis[0].maxInterval * (Math.ceil(chartOption.series.length / 5) + 1) + } + if (unit.type === 'Time' || unit.type === 'Date & Time') { + delete chartOption.yAxis[0].minInterval + delete chartOption.yAxis[0].maxInterval + } chartOption.yAxis[0].min = this.chartInfo.param.min ? this.chartInfo.param.min : undefined chartOption.yAxis[0].max = this.chartInfo.param.max ? this.chartInfo.param.max : undefined + chartOption.yAxis[0].axisLabel.formatter = this.yAxisLabelFormatter(minValue, maxValue, copies, unit, decimals) // 右y轴 if (this.chartInfo.param.enable.rightYAxis) { // 如果全都为右y轴数据 则右y轴显示网格 + const unit = chartDataFormat.getUnit(lodash.get(this, 'chartInfo.param.rightYAxis.unit', 2)) const allRight = this.series.every(item => item.yAxisIndex == 1) chartOption.yAxis[1].splitLine.show = allRight - - const unit = chartDataFormat.getUnit(lodash.get(this, 'chartInfo.param.rightYAxis.unit', 2)) + const rightData = this.chartData.filter(item => item[0].yAxisIndex) + console.log(rightData, unit) + const rightInfo = this.getMinMaxFromData(rightData, lodash.get(this, 'chartInfo.param.rightYAxis.unit', 2)) // + chartOption.yAxis[1].minInterval = chartDataFormat.Interval(rightInfo.maxValue, rightInfo.copies, rightInfo.unit.type, 'min') + chartOption.yAxis[1].maxInterval = chartDataFormat.Interval(rightInfo.maxValue, rightInfo.copies, rightInfo.unit.type, 'max') * Math.ceil(chartOption.series.length / 5) + if (this.chartInfo.param.stack) { + chartOption.yAxis[1].maxInterval = chartOption.yAxis[1].maxInterval * (Math.ceil(chartOption.series.length / 5) + 1) + } + if (unit.type === 'Time' || unit.type === 'Date & Time') { + delete chartOption.yAxis[1].minInterval + delete chartOption.yAxis[1].maxInterval + } chartOption.yAxis[1].axisLabel.formatter = this.yAxisLabelFormatter(undefined, undefined, undefined, unit, decimals) chartOption.yAxis[1].min = this.chartInfo.param.rightYAxis.min ? this.chartInfo.param.rightYAxis.min : undefined chartOption.yAxis[1].max = this.chartInfo.param.rightYAxis.max ? this.chartInfo.param.rightYAxis.max : undefined diff --git a/nezha-fronted/src/components/chart/chartDataFormat.js b/nezha-fronted/src/components/chart/chartDataFormat.js index 34343948b..0cc051f7b 100644 --- a/nezha-fronted/src/components/chart/chartDataFormat.js +++ b/nezha-fronted/src/components/chart/chartDataFormat.js @@ -369,6 +369,11 @@ function asciiCompute (num, ascii, units, dot = 2) { carry = parseInt(log) num = num / Math.pow(ascii, carry) } + // if (num > 255) { + // const log = Math.log(num) / Math.log(ascii) + // carry = parseInt(log) + // num = num / Math.pow(ascii, carry) + // } if (Number.isInteger(num)) { return num * SIGN + ' ' + units[carry] } else { @@ -847,6 +852,11 @@ export default { interVal = Math.ceil(interVal) * Math.pow(1024, pow) } interVal = !isNaN(interVal) ? interVal : 1 + if (interVal >= 1 && interVal <= 512) { + interVal = 512 + } else if (interVal > 512 && interVal <= 1024) { + interVal = 1024 + } return interVal } if (type === 'DataRate' || type === 'Misc') { diff --git a/nezha-fronted/src/components/chart/chartMixin.js b/nezha-fronted/src/components/chart/chartMixin.js index daa4999ef..aadee29fc 100644 --- a/nezha-fronted/src/components/chart/chartMixin.js +++ b/nezha-fronted/src/components/chart/chartMixin.js @@ -84,6 +84,7 @@ export default { this.isNoData = true originalDatas.forEach((originalData, expressionIndex) => { originalData.forEach((data, dataIndex) => { + console.log(data, 'data') if (colorIndex >= 20 && !this.showAllData) { colorIndex++ return @@ -97,6 +98,9 @@ export default { chartInfo.param.rightYAxis && chartInfo.param.rightYAxis.elementNames.forEach(item => { if (data.elements.name == item) { s.yAxisIndex = 1 + data.yAxisIndex = 1 + } else { + data.yAxisIndex = 0 } }) }