diff --git a/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue b/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue index 8951b4aab..be3107d5c 100644 --- a/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue +++ b/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue @@ -7,7 +7,7 @@ v-my-loading="chartLoading" >
{{chartInfo.param.rightYAxis.label}} @@ -72,6 +72,7 @@ export default { isStack: false, hasRightYAxis: false, chartLoading: false, + cursorDefault: false, tooltip: { x: 0, y: 0, @@ -247,6 +248,20 @@ export default { } } if (this.isInit) { + // 未设置dataLink的图表 鼠标样式为default + myChart.getZr().on('mousemove', (params) => { + // 获取鼠标在图表中的坐标 + const pointInPixel = [params.offsetX, params.offsetY] + const option = myChart.getOption() + const zoomState = this.$lodash.get(option, 'toolbox[0].feature.dataZoom.iconStatus.zoom', 'normal') + // 判断鼠标在坐标轴中且zoom未被激活 + if (myChart.containPixel('grid', pointInPixel) && zoomState === 'normal') { + this.cursorDefault = true + } else { + this.cursorDefault = false + } + }) + if (this.series.length > 1) { myChart.on('click', this.chartClick) myChart.on('mousedown', (params) => { @@ -257,27 +272,46 @@ export default { }) } - myChart.on('mouseover', (params) => { + // 鼠标滑过当前symbol 改变样式 + myChart.on('mousemove', (params) => { + if (this.series.length > 1) { + myChart.on('mousemove', () => { + this.cursorDefault = false + }) + } if (this.chartInfo.type !== 'point') { - if (this.tooltip.activeIndex != params.seriesIndex) { - const option = myChart.getOption() - option.series[params.seriesIndex].symbol = 'circle' - option.series[params.seriesIndex].itemStyle = { + const option = myChart.getOption() + const series = this.$lodash.cloneDeep(option.series) + series[params.seriesIndex].data[params.dataIndex] = { + symbol: 'circle', + itemStyle: { borderColor: this.hexToRgb(params.color, 0.4), borderWidth: 5 - } - myChart.setOption(option) + }, + value: params.value } + myChart.setOption({ series }) + myChart.dispatchAction( + { + type: 'highlight', + dataIndex: params.dataIndex + } + ) } this.tooltip.activeIndex = params.seriesIndex }) myChart.on('mouseout', (params) => { if (this.chartInfo.type !== 'point') { const option = myChart.getOption() - option.series.forEach(item => { - item.symbol = 'emptyCircle' + const series = this.$lodash.cloneDeep(option.series) + series.forEach(s => { + s.data.forEach((item, index) => { + if (item.itemStyle) { + s.data[index] = item.value + } + }) }) - myChart.setOption(option) + myChart.setOption({ series }) } this.tooltip.activeIndex = undefined }) @@ -472,7 +506,7 @@ export default { } const seriesName = nameArr.join('-') if (i === 0 && item.seriesName.indexOf('Previous') === -1 && type == 'left') { - const value = bus.computeTimezone(item.data[0] * 1000) + const value = bus.computeTimezone(item.value[0] * 1000) const tData = new Date(value) str += '