How to show only integer values on yAxis of HighChart?

wergeld picture wergeld · Jan 9, 2013 · Viewed 30.5k times · Source

We have a set of a data that contains counts of instances of events. These can only be integers. When we display data that has a high enough yValue the yAxis labels are integers. However, when we zoom in to ranges of data that have under y = 5 we see the tick markers show things like 0.5, 0.75, 1.5, etc. How can we force the yAxis labels to only show integer values?

Here is an example bit of code with some data. As you zoom in to the lower value region of the chart you can see what I mean. This is the current yAxis setup:

yAxis: {
  labels: {
    style: {
      fontSize: '9px',
      width: '175px'
    }
  },
  title: {
    text: ''
  }
},

Answer

Asad Saeeduddin picture Asad Saeeduddin · Jan 9, 2013

Set the allowDecimals option in the y axis to false in order to prevent non integer tick marks from being displayed:

yAxis: {
    allowDecimals: false,
    labels: {
        style: {
            fontSize: '9px',
            width: '175px'
        }
    },
    title: {
        text: ''
    }
}

Here is a demonstration: http://jsfiddle.net/sBC9K/