0

I can't explain this behavior :
Sometimes, my charts are displaying the first or the last label of the axis with a lot of decimals.

enter image description here enter image description here

In my graph options, here is how the yAxis look like :

yAxis : [{
     alternateGridColor: "white",
     gridLineColor : "#E3E3E3",
     lineWidth: 2,
     tickLength : 5, 
     lineColor : '#A5A5A5',
     tickWidth : 2,
     tickLength : 5,
     tickColor : '#A5A5A5',
     labels : {
         style : {
             fontWeight : 'bold',
             fontSize: '10px'
         }, 
         x : -labelMargin
     },
     tickPixelInterval: 20  
},
//more axis
]

How to fix that ? Any help appreciated.

zbMax
  • 2,756
  • 3
  • 21
  • 42

1 Answers1

1

You did not mentioned what should be the value of your labels so it uses the naive value for them that could be float number generated by a division perhaps.

I suggest you to handle your labels manually something like this:

    labels: {
        formatter: function () {
            return Math.floor(this.value)
        }
    }

As you can see i use floor() function to remove decimals.

muradin
  • 1,249
  • 2
  • 14
  • 34
  • 1
    I've added `format: '{value:.2f}'` and as expected, it prevents that strange behavior to appear again. But when the axis displays 'greater' values (I mean 1, 2, 3,..), I don't want the axis to display the decimals. Any tip? – zbMax Nov 14 '14 at 08:17
  • I think you can do mathematical operation again. For example according to my answer it should be something like: `return (this.value - Math.floor(this.value))` that takes the decimals apart. – muradin Nov 14 '14 at 10:10
  • @zbMax use a [label formatter](http://api.highcharts.com/highcharts#yAxis.labels.formatter) and [Highcharts.numberFormat](http://api.highcharts.com/highcharts#Highcharts.numberFormat) supported by any conditions which check a value. – Sebastian Bochan Nov 14 '14 at 10:39