Highcharts - best way to handle and display zero (or negative) values in a line chart series with logarithmic Y axis

前端 未结 2 1607
执念已碎
执念已碎 2020-12-19 07:39

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 fo

相关标签:
2条回答
  • 2020-12-19 08:44

    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;
                    }
                }
            }
        }
    });
    
    0 讨论(0)
  • 2020-12-19 08:45

    When dealing with huge numbers, it's better to use the standard label formatter for values other than 0, otherwise your labels gonna be displayed like this: 1000000000... To change this replace 'else' statement to the call to the original label formatter method below:

    var chart = new Highcharts.Chart({ 
        yAxis: {        
            labels: {
                formatter: function() {
                    if(this.value === 0.00001){
                        return 0;
                    } else {
                        return Highcharts.Axis.prototype.defaultLabelFormatter.call(this);
                    }
                }
            }
        }
    });
    
    0 讨论(0)
提交回复
热议问题