我有一个线系列,在该系列上我仅为系列中的特定值显示自定义数据标签。在窗口调整大小时,数据标签从图表中消失。有没有解决这个问题的方法。 提前致谢。
我的代码:
var options = {
chart : {
renderTo : 'container',
type : 'line',
},
xAxis : {
spacingTop: 50,
spacingBottom: 25,
categories : []
},
yAxis : [ {
min: 0,
minRange: 0.1
} ],
plotOptions: {
line:{
dataLabels: {
enabled:true,
defer:false,
formatter: function() {
count++;
if(this.y)
if(batch_info[count]!=0)
return batch_info[count];
}
}
}
},
series : []
};
`
在窗口调整大小之前:
最大化窗口后:
最佳答案
每次重绘/调整大小时都会调用格式化程序回调,因此最可能的情况是您没有重置 count
变量,结果它访问了不存在的值,例如batch_info[101]
当 batch_info.length === 100
时。
您可以使用模运算符来避免它:
formatter: function () {
count++;
return batch_info[count % batch_info.length];
}
示例:http://jsfiddle.net/ck8zhLmj/1/
但我建议重构代码并放弃使用 count
变量。相反,您可以在系列的数据或点对象中包含有关数据标签的信息。
关于javascript - Highcharts - 线系列中的自定义数据标签,在窗口调整大小时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40463860/