diff --git a/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue b/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue index 64b65f446..9f56eae9e 100644 --- a/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue +++ b/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue @@ -133,6 +133,11 @@ export default { this.isStack = this.chartInfo.param.stack } catch (e) {} const chartOption = lodash.cloneDeep(chartOptions) + + if (this.$lodash.get(this.chartInfo, 'param.enable.tooltip', false) && this.$lodash.get(this.chartInfo, 'param.tooltip.mode', 'all') === 'single') { + chartOption.tooltip.trigger = 'item' + } + // 防止tootip超出内容区域 if (this.from === 'integration' || this.from === 'dashboardTemp') { chartOption.tooltip.appendToBody = false @@ -367,6 +372,9 @@ export default { tooltipFormatter (hasTotal) { // 堆叠图需要total数据 const self = this return function (params) { + if (!params.length) { // tooltip mode为single + params = [params] + } const decimals = self.chartInfo.param.decimals || 2 let str = '
' // 区分左y轴右y轴 @@ -393,6 +401,32 @@ export default { if (!arr.length) { return } + + // tooltip排序 + let sortBy + if (self.$lodash.get(self.chartInfo, 'param.enable.tooltip') && self.$lodash.get(self.chartInfo, 'param.tooltip.mode') !== 'single' && self.$lodash.get(self.chartInfo, 'param.tooltip.sort') !== 'none') { + sortBy = self.$lodash.get(self.chartInfo, 'param.tooltip.sort') + } + const previousIndex = arr.findIndex(item => item.seriesName.indexOf('Previous') !== -1) + if (previousIndex != -1) { // 对比状态 + const arrNow = arr.slice(0, previousIndex) + const arrPrevious = arr.slice(previousIndex) + if (sortBy === 'asc') { + arrNow.sort((a, b) => a.data[1] - b.data[1]) + arrPrevious.sort((a, b) => a.data[1] - b.data[1]) + } else if (sortBy === 'desc') { + arrNow.sort((a, b) => b.data[1] - a.data[1]) + arrPrevious.sort((a, b) => b.data[1] - a.data[1]) + } + arr = [...arrNow, ...arrPrevious] + } else { + if (sortBy === 'asc') { + arr.sort((a, b) => a.data[1] - b.data[1]) + } else if (sortBy === 'desc') { + arr.sort((a, b) => b.data[1] - a.data[1]) + } + } + let sum = 0 let flag = true arr.forEach((item, i) => { diff --git a/nezha-fronted/src/components/chart/chart/options/chartTimeSeries.js b/nezha-fronted/src/components/chart/chart/options/chartTimeSeries.js index 6698e3118..384fa74ed 100644 --- a/nezha-fronted/src/components/chart/chart/options/chartTimeSeries.js +++ b/nezha-fronted/src/components/chart/chart/options/chartTimeSeries.js @@ -84,6 +84,9 @@ export const chartTimeSeriesLineOption = { }, axisTick: { show: false + }, + axisPointer: { + snap: true } }, yAxis: [ diff --git a/nezha-fronted/src/components/common/bottomBox/tabs/dashboardTab.vue b/nezha-fronted/src/components/common/bottomBox/tabs/dashboardTab.vue index a58189ee0..f40f0c28a 100644 --- a/nezha-fronted/src/components/common/bottomBox/tabs/dashboardTab.vue +++ b/nezha-fronted/src/components/common/bottomBox/tabs/dashboardTab.vue @@ -230,7 +230,8 @@ export default { valueMapping: false, thresholds: false, visibility: false, - rightYAxis: false + rightYAxis: false, + tooltip: true }, thresholdShow: true, thresholds: [{ value: undefined, color: randomcolor() }], @@ -249,7 +250,11 @@ export default { min: undefined, max: undefined }, - dataLink: [] + dataLink: [], + tooltip: { + mode: 'all', + sort: 'none' + } }, elements: [{ expression: '', legend: '', type: 'expert', id: '', name: 'A', state: 1, orderNum: 0 }], panel: '', @@ -432,14 +437,23 @@ export default { if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) { this.chart.param.collapse = false } - if ((this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') && !this.chart.param.rightYAxis) { - this.chart.param.rightYAxis = { - elementNames: [], - style: 'line', - unit: 2, - label: '', - min: undefined, - max: undefined + if (this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') { + if (!this.chart.param.rightYAxis) { + this.chart.param.rightYAxis = { + elementNames: [], + style: 'line', + unit: 2, + label: '', + min: undefined, + max: undefined + } + } + if (!this.chart.param.tooltip) { + this.chart.param.tooltip = { + mode: 'all', + sort: 'none' + } + this.chart.param.enable.tooltip = true } } if (this.chart.type === 'stat') { @@ -479,14 +493,23 @@ export default { if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) { this.chart.param.collapse = false } - if ((this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') && !this.chart.param.rightYAxis) { - this.chart.param.rightYAxis = { - elementNames: [], - style: 'line', - unit: 2, - label: '', - min: undefined, - max: undefined + if (this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') { + if (!this.chart.param.rightYAxis) { + this.chart.param.rightYAxis = { + elementNames: [], + style: 'line', + unit: 2, + label: '', + min: undefined, + max: undefined + } + } + if (!this.chart.param.tooltip) { + this.chart.param.tooltip = { + mode: 'all', + sort: 'none' + } + this.chart.param.enable.tooltip = true } } if (this.chart.type === 'stat') { diff --git a/nezha-fronted/src/components/common/rightBox/chart/chartConfig.vue b/nezha-fronted/src/components/common/rightBox/chart/chartConfig.vue index b549406a6..ef33d584b 100644 --- a/nezha-fronted/src/components/common/rightBox/chart/chartConfig.vue +++ b/nezha-fronted/src/components/common/rightBox/chart/chartConfig.vue @@ -448,7 +448,7 @@
-
+
{{$t('dashboard.dashboard.chartForm.rightYAxis')}}
+ +
+
+ {{$t('dashboard.dashboard.chartForm.tooltip')}} + +
+ +
+ + + + + + + + + + + + + + + +
+
+
+
@@ -1380,7 +1436,8 @@ export default { valueMapping: false, thresholds: false, visibility: false, - rightYAxis: false + rightYAxis: false, + tooltip: true }, showHeader: this.chartConfig.param.showHeader, visibility: { @@ -1397,7 +1454,11 @@ export default { min: undefined, max: undefined }, - dataLink: this.chartConfig.param.dataLink + dataLink: this.chartConfig.param.dataLink, + tooltip: { + mode: 'all', + sort: 'none' + } } this.$nextTick(() => { this.chartConfig.param.thresholds.push({ value: undefined, color: randomcolor() }) diff --git a/nezha-fronted/src/components/common/rightBox/chart/chartTypeShow.js b/nezha-fronted/src/components/common/rightBox/chart/chartTypeShow.js index 1311170bd..e778e62e8 100644 --- a/nezha-fronted/src/components/common/rightBox/chart/chartTypeShow.js +++ b/nezha-fronted/src/components/common/rightBox/chart/chartTypeShow.js @@ -239,7 +239,7 @@ export default { default: return false } }, - isShowRightYAxis (type) { + isTimeSeries (type) { switch (type) { case 'line': case 'area': diff --git a/nezha-fronted/src/components/page/dashboard/dashboard.vue b/nezha-fronted/src/components/page/dashboard/dashboard.vue index f6105eb8c..a75f114d5 100644 --- a/nezha-fronted/src/components/page/dashboard/dashboard.vue +++ b/nezha-fronted/src/components/page/dashboard/dashboard.vue @@ -247,7 +247,8 @@ export default { valueMapping: false, thresholds: false, visibility: false, - rightYAxis: false + rightYAxis: false, + tooltip: true }, thresholdShow: true, thresholds: [{ value: undefined, color: randomcolor() }], @@ -266,7 +267,11 @@ export default { min: undefined, max: undefined }, - dataLink: [] + dataLink: [], + tooltip: { + mode: 'all', + sort: 'none' + } }, elements: [{ expression: '', legend: '', type: 'expert', id: '', name: 'A', state: 1, orderNum: 0 }], panel: '', @@ -607,14 +612,23 @@ export default { if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) { this.chart.param.collapse = false } - if ((this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') && !this.chart.param.rightYAxis) { - this.chart.param.rightYAxis = { - elementNames: [], - style: 'line', - unit: 2, - label: '', - min: undefined, - max: undefined + if (this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') { + if (!this.chart.param.rightYAxis) { + this.chart.param.rightYAxis = { + elementNames: [], + style: 'line', + unit: 2, + label: '', + min: undefined, + max: undefined + } + } + if (!this.chart.param.tooltip) { + this.chart.param.tooltip = { + mode: 'all', + sort: 'none' + } + this.chart.param.enable.tooltip = true } } if (this.chart.type === 'stat') { @@ -654,14 +668,23 @@ export default { if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) { this.chart.param.collapse = false } - if ((this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') && !this.chart.param.rightYAxis) { - this.chart.param.rightYAxis = { - elementNames: [], - style: 'line', - unit: 2, - label: '', - min: undefined, - max: undefined + if (this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') { + if (!this.chart.param.rightYAxis) { + this.chart.param.rightYAxis = { + elementNames: [], + style: 'line', + unit: 2, + label: '', + min: undefined, + max: undefined + } + } + if (!this.chart.param.tooltip) { + this.chart.param.tooltip = { + mode: 'all', + sort: 'none' + } + this.chart.param.enable.tooltip = true } } if (this.chart.type === 'stat') {