dongqu9917
2017-07-17 08:46
浏览 779
已采纳

如何在Chartjs中将Y轴值从浮点数更改为整数?

i want to change Yaxis from real number to integer and here is image, and please help me solve this problem

enter image description here

here is my code

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
  }]
};

and here is my option for my chart

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
      }
    }
  });
});

图片转代码服务由CSDN问答提供 功能建议

我想将Yaxis从实数更改为整数,这里是图像,请帮我解决这个问题

这是我的代码

   var lineChartData = {
 labels:time,
数据集:[{
 label:“Sốngườiđăngkíủnghộ”,
 borderColor:window.chartColors.red,
 pointBackgroundColor:window.chartColors.red,\  n fill:false,
 data:people_isProcessing 
},{
 label:“Sốngườiđãủnghộ”,
 borderColor:window.chartColors.purple,
 pointBackgroundColor:window.chartColors.purple,
 fill  :false,
 data:people_isReceived 
}] 
}; 
   
 
 

这里是我的图表选项 < pre> window.onload = function(){ var chartEl = document.getElementById(“chart”); window.myLine = 新图表(chartEl,{ type:'line', data:lineChartData, options:{ title:{ display:true, text:'Kindmate - Chart Static Donate' } , 工具提示:{ enabled:true, mode:'index', position:'nearest', custom:customTooltips } } }); }); \ n

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongping9475 2017-07-17 08:54
    已采纳

    In your case, you can set stepSize property to 1 for y-axis ticks, to change the y-axis values from float number to integer.

    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>

    </div>
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongliyan7318 2017-07-17 08:53

    Try this:

    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
                        },
                          scales: {
                             yAxes: [{
                                 ticks: {
                                     beginAtZero: true,
                                     callback: function(value) {if (value % 1   === 0) {return value;}}
                                  }
                              }]
                         }
                    }
                });
    
    评论
    解决 1 无用
    打赏 举报

相关推荐 更多相似问题