Mehadi
Mehadi

Reputation: 105

Chart.js zoom shows decimal points

I have implemented graphs using Chart.js and zoom feature using chartjs-plugin-zoom which works fine. However, while scrolling the y-axes is giving a large range of decimal points which is resulting in the values being out of viewpoint. How do I avoid the decimal points?

Without Zoom: enter image description here

When Zoomed: enter image description here

chartjs-plugin-zoom code:

plugins: {
    zoom: {
        
        pan: {
                enabled: true,
        },
        zoom: {

        wheel: {
            enabled: true,
            speed: .01
        },
        pinch: {
            enabled: true
        },
        mode: 'xy',
        }
    },
},
 

Upvotes: 0

Views: 622

Answers (1)

kmoser
kmoser

Reputation: 9308

From https://github.com/chartjs/chartjs-plugin-zoom/issues/220#issuecomment-507543826

options: {
  scales: {
    yAxes: [{
      ticks: {
        callback: function(value) {
          if (Math.floor(value) === value) {
            return value
          }
        }
      }
     }]
   }
}

Upvotes: 2

Related Questions