fix: 修复折线图百分比数据与坐标对不上问题

This commit is contained in:
@changcode
2022-10-23 10:17:26 +08:00
parent 74cbcf0d46
commit 21c3ead654
4 changed files with 25 additions and 8 deletions

View File

@@ -291,7 +291,7 @@ export default {
}
])
},
data: t.data.map(v => [Number(v[0]) * 1000, Number(v[1]), 'number']),
data: t.data.map(v => [Number(v[0]) * 1000, Number(v[1]), 'number'])
}
})
this.chartOption.tooltip.formatter = (params) => {

View File

@@ -47,7 +47,7 @@ import { get } from '@/utils/http'
import { api } from '@/utils/api'
import ChartNoData from '@/views/charts/charts/ChartNoData'
import chartMixin from '@/views/charts2/chart-mixin'
import { chartColor3 } from '@/utils/constants'
import unitConvert from '@/utils/unit-convert'
export default {
name: 'NpmLine',
@@ -178,6 +178,14 @@ export default {
data: t.values.map((v) => [Number(v[0]) * 1000, Number(v[1]), type])
}
})
this.chartOption.yAxis[0].axisLabel.formatter = (value) => {
if (type === 'percent') {
console.log(type)
return unitConvert(value, type)[0]
} else {
return unitConvert(value, 'number').join('')
}
}
this.chartOption.tooltip.formatter = (params) => {
params.forEach(t => {
t.seriesName = this.$t(t.seriesName)

View File

@@ -286,6 +286,15 @@ export default {
this.chartOption = trafficLineChartOption
const chartOption = this.chartOption.series[0]
this.chartOption.series = echartsData.map((t, i) => {
this.chartOption.yAxis[0].axisLabel.formatter = (value) => {
if (t.unitType === 'percent') {
return unitConvert(value, t.unitType)[0]
} else if (t.unitType === 'time') {
return unitConvert(value, 'number').join('')
} else {
return unitConvert(value, t.unitType).join('')
}
}
return {
...chartOption,
name: this.$t(t.name),

View File

@@ -345,9 +345,9 @@ export const npmLineChartOption = {
show: false
},
axisLabel: {
formatter: function (value) {
return unitConvert(value, unitTypes.number).join('')
}
// formatter: function (value) {
// return unitConvert(value, unitTypes.number).join('')
// }
}
}
],
@@ -416,9 +416,9 @@ export const trafficLineChartOption = {
show: false
},
axisLabel: {
formatter: function (value) {
return unitConvert(value, unitTypes.number).join('')
}
// formatter: function (value) {
// return unitConvert(value, unitTypes.number).join('')
// }
}
}
],