Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
692 views
in Technique[技术] by (71.8m points)

javascript - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...