Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make integer scale in Chartjs

I'm trying to make a horizontal bar chart with an integer scale. As suggested in this question, I've tried to set scaleOverride, scaleSteps etc, but it seems not to be working. I tried to put them in dataset, in options, in xScales but nothing worked.

This jsfiddle shows what I tried to do.

like image 805
Berne Avatar asked May 17 '16 23:05

Berne


People also ask

What is utils in Chartjs?

The Utils file contains multiple helper functions that the chart. js sample pages use to generate charts. These functions are subject to change, including but not limited to breaking changes without prior notice. Because of this please don't rely on this file in production environments.

How do you change colors in Chartjs?

With ChartJS 3, you can change the color of the labels by setting the scales. x. ticks. color and scales.


1 Answers

The linked question is for Chart.js version 1.x. For the new version you need to use the ticks option. See http://www.chartjs.org/docs/#scales

   ...
   xAxes: [{
      ticks: {
        min: 0,
        stepSize: 1,
        max: 4
      },
      ...

Fiddle - https://jsfiddle.net/jkufz1b9/

like image 128
potatopeelings Avatar answered Oct 05 '22 16:10

potatopeelings