javascript - 如何在 chartjs 中将 Y 轴值从 float 更改为整数?

标签 javascript php laravel chart.js

我想把 Yaxis 从实数变成整数,这是图片,请帮我解决这个问题

enter image description here

这是我的代码

var lineChartData = {
  labels: time,
  datasets: [{
    label: "Số người đăng kí ủng hộ",
    borderColor: window.chartColors.red,
    pointBackgroundColor: window.chartColors.red,
    fill: false,
    data: people_isProcessing
  }, {
    label: "Số người đã ủng hộ",
    borderColor: window.chartColors.purple,
    pointBackgroundColor: window.chartColors.purple,
    fill: false,
    data: people_isReceived
  }]
};

这是我的图表选项

window.onload = function() {
  var chartEl = document.getElementById("chart");
  window.myLine = new Chart(chartEl, {
    type: 'line',
    data: lineChartData,
    options: {
      title: {
        display: true,
        text: 'Kindmate - Chart Static Donate'
      },
      tooltips: {
        enabled: true,
        mode: 'index',
        position: 'nearest',
        custom: customTooltips
      }
    }
  });
});

最佳答案

在您的情况下,您可以将 y 轴刻度的 stepSize 属性设置为 1,以更改从 float 到整数的 y 轴值。

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

ᴅᴇᴍᴏ

var chart = new Chart(ctx, {
   type: 'line',
   data: {
      labels: ['Jan', 'Feb', 'Mar', 'Apr'],
      datasets: [{
         label: '# of votes',
         data: [1, 2, 3, 4]
      }]
   },
   options: {
      scales: {
         yAxes: [{
            ticks: {
               stepSize: 1
            }
         }]
      }
   }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas id="ctx"></canvas>

关于javascript - 如何在 chartjs 中将 Y 轴值从 float 更改为整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45139641/

相关文章:

php - Sqlite 内部联接不起作用 :s

php - Laravel API 从速率限制中排除 1 个 IP 地址

laravel - 在javascript代码中重定向惯性js和jetstream

php - jquery tokeninput 插件错误为 "TypeError: term is undefined"

javascript - jQuery 自动滚动到最近的部分

javascript - 无法在其初始化程序中引用参数 'initialState'

php - 如何部署laravel宅基地环境

javascript - typescript 路由错误 - 没有与此调用匹配的过载

php - 创建对象时如何应用开闭原则

php - 设计一个PHP调试工具