请注意,对于一点,所有变量(tick、increment、dataMax)都等于0,因此
.我使用highcharts vue和xAxis.tickPositioner函数
chartOptions: {
chart: {
type: 'areaspline'
},
xAxis: {
tickPositioner: function () {
let positions = [],
tick = Math.floor(this.dataMin),
increment = Math.ceil((this.dataMax - this.dataMin) / 10)
if (this.dataMax !== null && this.dataMin !== null) {
for (tick; tick <= this.dataMax; tick += increment) {
positions.push(tick)
}
}
return positions
}
},
series: [],
categories: []
}
mounted(){
this.chartOptions.series = [
{name: 'test1', data: [1]},
{name: 'test2', data: [2]}
]
this.chartOptions.xAxis.categories = ['category1']
}
<highcharts :options="chartOptions"></highcharts>
我需要它,因为通常我有很多数据点。如果这个.chatOptions.series[i].data.length>1.但如果这个.chatOptions.series[i].data.length==1,浏览器就会崩溃。我能做些什么来修复它?
for
是一个无穷大循环。
您可以在此处查看:https://jsfiddle.net/BlackLabel/35suo8k0/
作为解决方案,您可以使用以下代码:
xAxis: {
tickPositioner() {
let positions = [],
tick = Math.floor(this.dataMin),
increment = Math.ceil((this.dataMax - this.dataMin) / 10)
if (this.dataMax && this.dataMin) {
for (tick; tick <= this.dataMax; tick += increment) {
positions.push(tick)
}
}
return positions
}
},
我更改了if条件,现在它检查dataMax和dataMin是否存在。
演示:https://jsfiddle.net/BlackLabel/k6vj9af8/
我通过以下更改修复了它:
tickPositioner: function () {
let positions = [],
tick = Math.floor(this.dataMin),
increment = Math.ceil((this.dataMax - this.dataMin) / 10)
if (this.dataMax === 0) {
positions = [0]
} else if (this.dataMax !== null && this.dataMin !== null) {
for (tick; tick <= this.dataMax; tick += increment) {
positions.push(tick)
}
}
return positions
}