问题描述
在我的HighChart线图中,系列数据是从我的Ruby on Rails应用程序动态提供的。有时系列值是零或更少,这是HighCharts的问题,它会引发以下异常:
Highcharts错误#10
无法在对数轴上绘制零或零值
所以作为解决方法,我处理我的红宝石数组,以有条件地用一个微不足道的正数代替零值,例如0.00001,如下所示:
oil_vol_array = d_array [1] .map {| e | (e
这样可以防止引发异常,但显示屏显示如果起始值为零,可以从0.0001开始(可以理解,因为我问过它)。更理想的显示方法是将图形设置为零,但HighChart不喜欢它:(b / b)
有没有办法实现这一点?
您是否尝试过使用?
var chart = new Highcharts.Chart({
yAxis:{
标签:{
formatter:function(){
if(this.value === 0.00001){
return 0;
} else {
返回this.value;
}
}
}
}
});
In my HighChart line graphs, the series data is being fed from my Ruby on Rails application dynamically. Sometimes the series values are zeros or less which is a problem for HighCharts and it throws the following exception:
Highcharts Error #10
Can't plot zero or subzero values on a logarithmic axis
So as a work-around, I process my ruby array to conditionally replace a zero of less value with an insignificant positive number, .e.g. 0.00001 as shown below:
oil_vol_array = d_array[1].map { |e| (e < 0.0001) ? 0.0001 : e.round(3) }
This prevents the exception being thrown, but the display shows the graph starting at 0.0001 if the starting value is zero (understandably so, since I asked it to). A more desirable display would be to start the graph at zero, but HighChart doesn't like it :(
Is there a way that this can be achieved?
Have you tried using a label formatter?
var chart = new Highcharts.Chart({
yAxis: {
labels: {
formatter: function() {
if(this.value === 0.00001){
return 0;
} else {
return this.value;
}
}
}
}
});
这篇关于Highcharts - 处理和显示具有对数Y轴的折线图系列中零(或负)值的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!