fix: 修改多次刷新图表 堆叠事件重复添加的问题

This commit is contained in:
zhangyu
2021-11-27 13:41:26 +08:00
parent aa6c4f16c2
commit 62ab3ef6bd
3 changed files with 139 additions and 140 deletions

View File

@@ -829,6 +829,7 @@ export default {
// chartSite用于区分是全屏显示还是局部显示
initChart (chartInfo, dataArg, ele, legend) {
const self = this
self.isStackArea = false
let minTime = null
let maxTime = null
if (dataArg.length > 0 && dataArg[0].data &&
@@ -936,31 +937,30 @@ export default {
str += '<br/>'
}
showFlag = showFlag || item.data[1]
if (isNaN(item.data[1] + '')) {
return
if (!isNaN(item.data[1] + '')) {
const val = formatScientificNotation(item.data[1], 2)
sum += isNaN(self.numberWithEConvent(val)) ? 0 : Number(self.numberWithEConvent(val))
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += `<div style="max-width: 500px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;"><span style='display:inline-block;margin-right:5px;border-radius:10px;width:15px;height:5px;background-color: ${color};}'></span>${tip ? (tip.alias ? tip.alias : tip.name) : item.seriesName} </div>`
str += '<div style="padding-left: 10px;">'
str += (function () {
if (chartInfo.from == 'endpoint') {
return val == 1 ? 'up' : 'down'
}
return chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(val, null, 2)
}())
str += '</div>'
str += '</div>'
}
const val = formatScientificNotation(item.data[1], 2)
sum += isNaN(self.numberWithEConvent(val)) ? 0 : Number(self.numberWithEConvent(val))
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += `<div style="max-width: 500px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;"><span style='display:inline-block;margin-right:5px;border-radius:10px;width:15px;height:5px;background-color: ${color};}'></span>${tip ? (tip.alias ? tip.alias : tip.name) : item.seriesName} </div>`
str += '<div style="padding-left: 10px;">'
str += (function () {
if (chartInfo.from == 'endpoint') {
return val == 1 ? 'up' : 'down'
}
return chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(val, null, 2)
}())
str += '</div>'
str += '</div>'
})
if (chartInfo.type === 'stackArea' || self.isStackArea) {
sum = parseFloat(Number(sum).toFixed(2))
sum = parseFloat(Number(sum).toFixed(6))
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += '<div style="line-height: 18px; font-size: 12px;padding-left:20px;">'
str += self.$t('dashboard.panel.chartTotal')
str += '</div>'
str += '<div style="padding-left: 10px;">'
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(sum, null, 2)
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(sum, null, 6)
str += '</div>'
str += '</div>'
}
@@ -1088,6 +1088,7 @@ export default {
this.$refs.loadingPreview.endLoading()
})
this.echartModalStore.off('magictypechanged')
this.echartModalStore.on('magictypechanged', function (params) {
self.isStackArea = !self.isStackArea
if (self.isStackArea) {

View File

@@ -647,6 +647,7 @@ export default {
this.legendMagicType = legend
this.chartInfo = chartInfo
const self = this
self.isStackArea = false
this.chartType = '' // 图表类型
if (chartInfo.type === 4) { // line,bar
this.chartType = 'line'
@@ -837,49 +838,48 @@ export default {
minusFlag = false
}
showFlag = showFlag || item.data[1]
if (isNaN(item.data[1] + '')) {
return
}
const previousItem = params.find((series) => ('Previous ' + item.seriesName) === series.seriesName)
let paramsDot = bus.countDecimals(item.data[1])
if (paramsDot < self.chartDot) {
paramsDot = self.chartDot
} else if (paramsDot > 6) {
paramsDot = 6
}
const val = formatScientificNotation(item.data[1], paramsDot)
sum += isNaN(self.numberWithEConvent(val)) ? 0 : Number(self.numberWithEConvent(val))
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += `<div style="max-width: 500px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;"><span style='display:inline-block;margin-right:5px;border-radius:10px;width:15px;height:5px;background-color: ${color};}'></span>${tip ? (tip.alias ? tip.alias : tip.name) : item.seriesName} </div>`
str += '<div style="padding-left: 10px;min-width: 75px;text-align: right">'
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(val, null, -1, paramsDot)
if (previousItem) {
str += '<span style="padding-left: 10px; display: inline-block;width: 65px;text-align: right;box-sizing: border-box;padding-right: 10px">'
const previousval = formatScientificNotation(previousItem.data[1], paramsDot)
let minusVal = 0
if (previousval <= val) {
minusVal = val - previousval
str += '+'
} else {
minusVal = previousval - val
str += '-'
if (!isNaN(item.data[1] + '')) {
const previousItem = params.find((series) => ('Previous ' + item.seriesName) === series.seriesName)
let paramsDot = bus.countDecimals(item.data[1])
if (paramsDot < self.chartDot) {
paramsDot = self.chartDot
} else if (paramsDot > 6) {
paramsDot = 6
}
const val = formatScientificNotation(item.data[1], paramsDot)
sum += isNaN(self.numberWithEConvent(val)) ? 0 : Number(self.numberWithEConvent(val))
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(minusVal, null, -1, paramsDot)
str += '</span>'
} else if (tip.alias.indexOf('Previous ') !== -1) {
str += '<span style="padding-left: 10px; display: inline-block;width: 65px;text-align: right">'
str += '</span>'
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += `<div style="max-width: 500px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;"><span style='display:inline-block;margin-right:5px;border-radius:10px;width:15px;height:5px;background-color: ${color};}'></span>${tip ? (tip.alias ? tip.alias : tip.name) : item.seriesName} </div>`
str += '<div style="padding-left: 10px;min-width: 75px;text-align: right">'
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(val, null, -1, paramsDot)
if (previousItem) {
str += '<span style="padding-left: 10px; display: inline-block;width: 65px;text-align: right;box-sizing: border-box;padding-right: 10px">'
const previousval = formatScientificNotation(previousItem.data[1], paramsDot)
let minusVal = 0
if (previousval <= val) {
minusVal = val - previousval
str += '+'
} else {
minusVal = previousval - val
str += '-'
}
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(minusVal, null, -1, paramsDot)
str += '</span>'
} else if (tip.alias.indexOf('Previous ') !== -1) {
str += '<span style="padding-left: 10px; display: inline-block;width: 65px;text-align: right">'
str += '</span>'
}
str += '</div>'
str += '</div>'
}
str += '</div>'
str += '</div>'
})
if (self.data.type === 'stackArea' || self.isStackArea) {
if (!self.stackTotalColor || self.stackTotalColor == '') {
self.stackTotalColor = randomcolor()
}
sum = parseFloat(Number(sum).toFixed(2))
sum = parseFloat(Number(sum).toFixed(6))
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += '<div style="line-height: 18px; font-size: 12px;padding-left:0px;">'
str += `<span style='display:inline-block;margin-right:5px;border-radius:10px;width:15px;height:5px;background-color: ${self.stackTotalColor};}'></span>`
@@ -1101,6 +1101,7 @@ export default {
}, 800)
window.addEventListener('resize', this.chartResize)
getChart(this.chartIndex).off('magictypechanged')
getChart(this.chartIndex).on('magictypechanged', function (params) {
self.isStackArea = !self.isStackArea
if (self.isStackArea) {
@@ -1152,26 +1153,25 @@ export default {
str += '</div>'
}
showFlag = showFlag || item.data[1]
if (isNaN(item.data[1] + '')) {
return
if (!isNaN(item.data[1] + '')) {
const val = formatScientificNotation(item.data[1], 2)
sum += isNaN(self.numberWithEConvent(val)) ? 0 : Number(self.numberWithEConvent(val))
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += `<div style="max-width: 500px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;"><span style='display:inline-block;margin-right:5px;border-radius:10px;width:15px;height:5px;background-color: ${color};}'></span>${tip ? (tip.alias ? tip.alias : tip.name) : item.seriesName} </div>`
str += '<div style="padding-left: 10px;">'
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(val, null, -1, paramsDot)
str += '</div>'
str += '</div>'
}
const val = formatScientificNotation(item.data[1], 2)
sum += isNaN(self.numberWithEConvent(val)) ? 0 : Number(self.numberWithEConvent(val))
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += `<div style="max-width: 500px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;"><span style='display:inline-block;margin-right:5px;border-radius:10px;width:15px;height:5px;background-color: ${color};}'></span>${tip ? (tip.alias ? tip.alias : tip.name) : item.seriesName} </div>`
str += '<div style="padding-left: 10px;">'
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(val, null, -1, paramsDot)
str += '</div>'
str += '</div>'
})
if (self.data.type === 'stackArea' || self.isStackArea) {
sum = parseFloat(Number(sum).toFixed(2))
sum = parseFloat(Number(sum).toFixed(6))
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += '<div style="line-height: 18px; font-size: 12px;padding-left:20px;">'
str += self.$t('dashboard.panel.chartTotal')
str += '</div>'
str += '<div style="padding-left: 10px;">'
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(sum, null, 2)
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(sum, null, self.chartDot)
str += '</div>'
str += '</div>'
}
@@ -1276,7 +1276,7 @@ export default {
self.echartModalStore.off('finished')
})
}, 100)
this.echartModalStore.off('magictypechanged')
this.echartModalStore.on('magictypechanged', function (params) {
self.isStackArea = !self.isStackArea
if (self.isStackArea) {
@@ -1337,54 +1337,53 @@ export default {
minusFlag = false
}
showFlag = showFlag || item.data[1]
if (isNaN(item.data[1] + '')) {
return
}
const previousItem = params.find((series) => ('Previous ' + item.seriesName) === series.seriesName)
const val = formatScientificNotation(item.data[1], 2)
sum += isNaN(self.numberWithEConvent(val)) ? 0 : Number(self.numberWithEConvent(val))
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += `<div style="max-width: 500px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;"><span style='display:inline-block;margin-right:5px;border-radius:10px;width:15px;height:5px;background-color: ${color};}'></span>${tip ? (tip.alias ? tip.alias : tip.name) : item.seriesName} </div>`
str += '<div style="padding-left: 10px;min-width: 75px;text-align: right">'
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(val, null, self.chartDot)
if (previousItem) {
str += '<span style="padding-left: 10px; display: inline-block;width: 65px;text-align: right;box-sizing: border-box;padding-right: 10px">'
const previousval = formatScientificNotation(previousItem.data[1], 2)
let minusVal = 0
if (previousval <= val) {
minusVal = val - previousval
str += '+'
} else {
minusVal = previousval - val
str += '-'
}
if (!isNaN(item.data[1] + '')) {
const previousItem = params.find((series) => ('Previous ' + item.seriesName) === series.seriesName)
const val = formatScientificNotation(item.data[1], 2)
sum += isNaN(self.numberWithEConvent(val)) ? 0 : Number(self.numberWithEConvent(val))
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += `<div style="max-width: 500px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;"><span style='display:inline-block;margin-right:5px;border-radius:10px;width:15px;height:5px;background-color: ${color};}'></span>${tip ? (tip.alias ? tip.alias : tip.name) : item.seriesName} </div>`
str += '<div style="padding-left: 10px;min-width: 75px;text-align: right">'
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(val, null, self.chartDot)
if (previousItem) {
str += '<span style="padding-left: 10px; display: inline-block;width: 65px;text-align: right;box-sizing: border-box;padding-right: 10px">'
const previousval = formatScientificNotation(previousItem.data[1], 2)
let minusVal = 0
if (previousval <= val) {
minusVal = val - previousval
str += '+'
} else {
minusVal = previousval - val
str += '-'
}
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(minusVal, null, self.chartDot)
str += '</span>'
} else if (tip.alias.indexOf('Previous ') !== -1) {
str += '<span style="padding-left: 10px; display: inline-block;width: 65px;text-align: right">'
str += '</span>'
}
str += '</div>'
if (previousItem) {
str += '<div style="padding-left: 10px;">'
const previousval = formatScientificNotation(previousItem.data[1], 2)
let minusVal = 0
if (previousval <= val) {
minusVal = val - previousval
str += '+'
} else {
minusVal = previousval - val
str += '-'
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(minusVal, null, self.chartDot)
str += '</span>'
} else if (tip.alias.indexOf('Previous ') !== -1) {
str += '<span style="padding-left: 10px; display: inline-block;width: 65px;text-align: right">'
str += '</span>'
}
str += '</div>'
if (previousItem) {
str += '<div style="padding-left: 10px;">'
const previousval = formatScientificNotation(previousItem.data[1], 2)
let minusVal = 0
if (previousval <= val) {
minusVal = val - previousval
str += '+'
} else {
minusVal = previousval - val
str += '-'
}
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(minusVal, null, self.chartDot)
str += chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(minusVal, null, self.chartDot)
str += '</div>'
}
str += '</div>'
}
str += '</div>'
})
if (self.data.type === 'stackArea' || self.isStackArea) {
sum = parseFloat(Number(sum).toFixed(2))
sum = parseFloat(Number(sum).toFixed(6))
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += '<div style="line-height: 18px; font-size: 12px;padding-left:20px;">'
str += self.$t('dashboard.panel.chartTotal')

View File

@@ -438,43 +438,42 @@ export default {
minusFlag = false
}
showFlag = showFlag || item.data[1]
if (isNaN(item.data[1] + '')) {
return
}
const val = Number(item.data[1])
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += `<div style="max-width: 500px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;"><span style='display:inline-block;margin-right:5px;border-radius:10px;width:15px;height:5px;background-color: ${item.color};}'></span>${alias || item.seriesName}: </div>`
str += '<div style="padding-left: 10px;">'
let dot = bus.countDecimals(val)
// console.log(dot,val)
if (dot < this.chartDot) {
dot = this.chartDot
} else if (dot > 6) {
dot = 6
}
str += chartDataFormat.getUnit(this.unit).compute(val, null, -1, dot)
const previousItem = params.find((series) => ('Previous ' + item.seriesName) === series.seriesName)
if (previousItem) {
str += '<span style="padding-left: 10px; display: inline-block;width: 65px;text-align: right;box-sizing: border-box;padding-right: 10px">'
const previousval = formatScientificNotation(previousItem.data[1], dot)
let minusVal = 0
if (previousval <= val) {
minusVal = val - previousval
str += '+'
} else {
minusVal = previousval - val
str += '-'
if (!isNaN(item.data[1] + '')) {
const val = Number(item.data[1])
str += '<div style="white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;display: flex; justify-content: space-between; min-width: 150px; max-width: 600px; line-height: 18px; font-size: 12px;">'
str += `<div style="max-width: 500px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;"><span style='display:inline-block;margin-right:5px;border-radius:10px;width:15px;height:5px;background-color: ${item.color};}'></span>${alias || item.seriesName}: </div>`
str += '<div style="padding-left: 10px;">'
let dot = bus.countDecimals(val)
// console.log(dot,val)
if (dot < this.chartDot) {
dot = this.chartDot
} else if (dot > 6) {
dot = 6
}
str += chartDataFormat.getUnit(this.unit).compute(val, null, -1, dot)
const previousItem = params.find((series) => ('Previous ' + item.seriesName) === series.seriesName)
if (previousItem) {
str += '<span style="padding-left: 10px; display: inline-block;width: 65px;text-align: right;box-sizing: border-box;padding-right: 10px">'
const previousval = formatScientificNotation(previousItem.data[1], dot)
let minusVal = 0
if (previousval <= val) {
minusVal = val - previousval
str += '+'
} else {
minusVal = previousval - val
str += '-'
}
str += chartDataFormat.getUnit(this.unit).compute(minusVal, null, -1, dot)
str += '</span>'
} else if (alias.indexOf('Previous ') !== -1) {
str += '<span style="padding-left: 10px; display: inline-block;width: 100px;text-align: right">'
str += '</span>'
str += chartDataFormat.getUnit(this.unit).compute(minusVal, null, -1, dot)
str += '</span>'
} else if (alias.indexOf('Previous ') !== -1) {
str += '<span style="padding-left: 10px; display: inline-block;width: 100px;text-align: right">'
str += '</span>'
}
str += '</div>'
str += '</div>'
}
str += '</div>'
str += '</div>'
})
str += '</div>'
if (!showFlag) {