首页 > 解决方案 > 我怎样才能只显示整数标签?

问题描述

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

图表

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',
        }
      }]
    }
  }
});

其他问题的新问题

标签: javascriptchart.js

解决方案


推荐阅读