如何在 Chartjs 中制作整数刻度 [英] How to make integer scale in Chartjs

查看:14
本文介绍了如何在 Chartjs 中制作整数刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作具有整数比例的水平条形图.正如 this question 中的建议,我尝试设置 scaleOverridescaleSteps 等,但它似乎不起作用.我试图将它们放在数据集、选项中、xScales 中,但没有任何效果.

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.

这个 jsfiddle 展示了我尝试做的事情.

This jsfiddle shows what I tried to do.

推荐答案

链接的问题是针对 Chart.js 版本 1.x.对于新版本,您需要使用 ticks 选项.请参阅 http://www.chartjs.org/docs/#scales

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
      },
      ...

<小时>

小提琴 - https://jsfiddle.net/jkufz1b9/

这篇关于如何在 Chartjs 中制作整数刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆