我怎样才能只显示整数标签?

时间:2021-02-26 06:11:41

标签: javascript chart.js

我的图表有 100 个标签。这些标签是从 0 到 10。一些标签是十进制的。但我只想在图表上看到整数。如何隐藏小数点?你可以在下面查看我的图片和代码。

chart

var timeLabels = [];

for (let j = 0; j <= scheduling.totalPeriod; j++) {
  timeLabels.push(j / 10);
}

var schedulingChart = new Chart(ctx, {
  type: 'line',
  data: {
    labels: timeLabels,
    datasets: [{
      steppedLine: true,
      label: scheduling.process[i].name,
      data: scheduling.process[i].chart,
      backgroundColor: ['rgba(255, 255, 255, 0.5)'],
      borderColor: ['rgba(255, 255, 255, 1)'],
      borderWidth: 1,
      pointBackgroundColor: 'green',
      pointBorderColor: 'black',
      pointRadius: 4
    }]
  },
  options: {
    maintainAspectRatio: false,
    scales: {
      yAxes: [{
        gridLines: {
          color: 'rgba(0, 0, 0, 0.5)',
        },
        ticks: {
          stepSize: 1,
          fontColor: 'rgba(255, 255, 255, 1)'
        }
      }],
      xAxes: [{
        gridLines: {
          color: 'rgba(0, 0, 0, 0.5)',
        },
        ticks: {
          fontColor: 'white',
        }
      }]
    }
  }
});

New for other problem

0 个答案:

没有答案