fix: 图表重复点击tab坍缩问题

This commit is contained in:
chenj
2022-12-05 20:12:04 +08:00
parent 064001c4ab
commit c7366ef745
2 changed files with 56 additions and 55 deletions

View File

@@ -375,13 +375,11 @@ export default {
if (this.myChart) { if (this.myChart) {
this.myChart.dispose() this.myChart.dispose()
} }
this.myChart = echarts.init(dom)
} else { } else {
dom = document.getElementById('link-traffic-sankey-1') dom = document.getElementById('link-traffic-sankey-1')
if (this.myChart2) { if (this.myChart2) {
this.myChart2.dispose() this.myChart2.dispose()
} }
this.myChart2 = echarts.init(dom)
} }
this.chartOption = this.$_.cloneDeep(linksTrafficSankeyOption) this.chartOption = this.$_.cloneDeep(linksTrafficSankeyOption)
this.chartOption.tooltip.formatter = function (param) { this.chartOption.tooltip.formatter = function (param) {
@@ -413,11 +411,15 @@ export default {
} }
this.chartOption.series[0].data = data this.chartOption.series[0].data = data
this.chartOption.series[0].links = links this.chartOption.series[0].links = links
if (tab === 0) { this.$nextTick(() => {
this.myChart.setOption(this.chartOption) if (tab === 0) {
} else { this.myChart = echarts.init(dom)
this.myChart2.setOption(this.chartOption) this.myChart.setOption(this.chartOption)
} } else {
this.myChart2 = echarts.init(dom)
this.myChart2.setOption(this.chartOption)
}
})
}, },
resize () { resize () {
if (this.tab === 0) { if (this.tab === 0) {

View File

@@ -388,12 +388,9 @@ export default {
// 此处为验证是否因dom未销毁导致图表出错后续可能会改 // 此处为验证是否因dom未销毁导致图表出错后续可能会改
let dom = null let dom = null
dom = document.getElementById('overviewLineChart') dom = document.getElementById('overviewLineChart')
// this.myChart = null
if (this.myChart) { if (this.myChart) {
this.myChart.dispose() this.myChart.dispose()
this.myChart = null
} }
this.myChart = echarts.init(dom)
this.chartOption = stackedLineChartOption this.chartOption = stackedLineChartOption
const chartOption = this.chartOption.series[0] const chartOption = this.chartOption.series[0]
this.chartOption.series = echartsData.map((t, i) => { this.chartOption.series = echartsData.map((t, i) => {
@@ -491,52 +488,54 @@ export default {
return str return str
} }
this.showMarkLine = true this.showMarkLine = true
this.myChart.setOption(this.chartOption) this.$nextTick(() => {
this.myChart = echarts.init(dom)
// 设置参见官网https://echarts.apache.org/zh/api.html#action.brush.brush this.myChart.setOption(this.chartOption)
this.myChart.dispatchAction({ // 设置参见官网https://echarts.apache.org/zh/api.html#action.brush.brush
// 刷选模式的开关。使用此 action 可将当前鼠标变为可刷选状态。事实上,点击 toolbox 中的 brush 按钮时,就是通过这个 action将当前普通鼠标变为刷选器的。 this.myChart.dispatchAction({
type: 'takeGlobalCursor', // 刷选模式的开关。使用此 action 可将当前鼠标变为可刷选状态。事实上,点击 toolbox 中的 brush 按钮时,就是通过这个 action将当前普通鼠标变为刷选器的。
// 如果想变为“可刷选状态”,必须设置。不设置则会关闭“可刷选状态”。 type: 'takeGlobalCursor',
key: 'brush', // 如果想变为“可刷选状态”,必须设置。不设置则会关闭“可刷选状态”。
brushOption: { key: 'brush',
// 参见 brush 组件的 brushType。如果设置为 false 则关闭“可刷选状态”。 brushOption: {
brushType: 'lineX', // 参见 brush 组件的 brushType。如果设置为 false 则关闭“可刷选状态”。
xAxisIndex: 'all', brushType: 'lineX',
// 单击清除选框 xAxisIndex: 'all',
brushMode: 'single', // 单击清除选框
// 选择完毕再返回所选数据 brushMode: 'single',
throttleType: 'debounce' // 选择完毕再返回所选数据
} throttleType: 'debounce'
})
const self = this
this.myChart.on('brushEnd', function (params) {
self.myChart.dispatchAction({
type: 'brush',
areas: [] // 删除选框
})
if (!self.mouseDownFlag) {
// 避免点击空白区域报错
if (params.areas !== undefined && params.areas.length > 0) {
self.brushHistory.unshift({
startTime: _.cloneDeep(self.timeFilter.startTime) * 1000,
endTime: _.cloneDeep(self.timeFilter.endTime) * 1000
})
const rangeObj = {
startTime: Math.ceil(params.areas[0].coordRange[0]),
endTime: Math.ceil(params.areas[0].coordRange[1])
}
// todo 目前暂定框选最小范围为5分钟后续可能会变动
if (rangeObj.endTime - rangeObj.startTime < 5 * 60 * 1000) {
rangeObj.startTime = rangeObj.endTime - 5 * 60 * 1000
}
_this.$store.commit('setRangeEchartsData', rangeObj)
} }
} })
const self = this
this.myChart.on('brushEnd', function (params) {
self.myChart.dispatchAction({
type: 'brush',
areas: [] // 删除选框
})
if (!self.mouseDownFlag) {
// 避免点击空白区域报错
if (params.areas !== undefined && params.areas.length > 0) {
self.brushHistory.unshift({
startTime: _.cloneDeep(self.timeFilter.startTime) * 1000,
endTime: _.cloneDeep(self.timeFilter.endTime) * 1000
})
const rangeObj = {
startTime: Math.ceil(params.areas[0].coordRange[0]),
endTime: Math.ceil(params.areas[0].coordRange[1])
}
// todo 目前暂定框选最小范围为5分钟后续可能会变动
if (rangeObj.endTime - rangeObj.startTime < 5 * 60 * 1000) {
rangeObj.startTime = rangeObj.endTime - 5 * 60 * 1000
}
_this.$store.commit('setRangeEchartsData', rangeObj)
}
}
})
}) })
}, },
activeChange (item, index) { activeChange (item, index) {