【问题标题】:How to make y axis only integer scaling in ChartJS?如何在 ChartJS 中使 y 轴仅进行整数缩放?
【发布时间】:2017-05-18 20:46:35
【问题描述】:

我只是 ChartJS 的新手,enter image description here

我有 3 个问题:

1.如何使Y轴只有整数?我应该在哪里添加它?

2.如何关闭标题“我的未决案例”?我尝试将其设置为null但不起作用?

3.如何关闭背景网格?看起来很奇怪

这是我的代码:

 var columnChart = document.getElementById("columnChart").getContext('2d');
        var myChart = new Chart(columnChart, {
            type: 'bar',
            data: {

                labels: columnChartLabel,
                datasets: [ {
                    label: 'My Open Case',
                    data: columnChartNumber,
                    backgroundColor: "rgba(255,153,0,1)"
                }]
            }

        });

【问题讨论】:

    标签: javascript charts bar-chart chart.js


    【解决方案1】:

    我怎样才能使 Y 轴只有整数?我应该在哪里添加它?

    您可以通过在图表选项中为 ticksstepSize 属性设置为 1 来使 Y 轴仅为整数。

    options: {
       scales: {
          yAxes: [{
             ticks: {
                stepSize: 1
             }
          }]
       }
    }
    

    tick configuration options

    如何关闭“我的未决案例”的标题?

    您可以通过将图例display属性设置为false来关闭标题(又名图例)

    options: {
       legend: {
          display: false
       }
    }
    

    legend configuration

    如何关闭背景网格?

    您可以通过将 gridLines 的 x 轴和 y 轴的 display 属性设置为 false 来关闭背景网格。

    options: {
       scales: {
          xAxes: [{
             gridLines: {
                display: false
             }
          }],
          yAxes: [{
             gridLines: {
                display: false
             }
          }]
       }
    }
    

    grid line configuration

    ᴡᴏʀᴋɪɴɢ ᴇxᴀᴍᴘʟᴇ ᴏɴ ᴊꜱꜰɪᴅᴅʟᴇ

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-30
    • 2017-12-21
    • 2012-10-12
    • 1970-01-01
    相关资源
    最近更新 更多