How to set max and min value for Y axis

后端 未结 17 2039
既然无缘
既然无缘 2020-11-27 11:08

I am using line chart from http://www.chartjs.org/ \"enter

As you can see max value (1

相关标签:
17条回答
  • 2020-11-27 11:18

    > Best Solution


      "options":{
                        scales: {
                                    yAxes: [{
                                        display: true,
                                        ticks: {
                                            suggestedMin: 0, //min
                                            suggestedMax: 100 //max 
                                        }
                                    }]
                                }
                        }
    
    0 讨论(0)
  • 2020-11-27 11:18

    There's so many conflicting answers to this, most of which had no effect for me.

    I was finally able to set (or retrieve current) X-axis minimum & maximum displayed values with chart.options.scales.xAxes[0].ticks.min (even if min & max are only a subset of the data assigned to the chart.)

    Using a time scale in my case, I used:

    chart.options.scales.xAxes[0].ticks.min = 1590969600000;  //Jun 1, 2020
    chart.options.scales.xAxes[0].ticks.max = 1593561600000;  //Jul 1, 2020
    chart.update();
    

    (I found no need to set the step values or beginAtZero, etc.)

    0 讨论(0)
  • 2020-11-27 11:19

    Since none of the suggestions above helped me with charts.js 2.1.4, I solved it by adding the value 0 to my data set array (but no extra label):

    statsData.push(0);
    
    [...]
    
    var myChart = new Chart(ctx, {
        type: 'horizontalBar',
        data: {
            datasets: [{
                data: statsData,
    [...]
    
    0 讨论(0)
  • 2020-11-27 11:20

    The above answers didn't work for me. Possibly the option names were changed since '11, but the following did the trick for me:

    ChartJsProvider.setOptions
      scaleBeginAtZero: true
    
    0 讨论(0)
  • 2020-11-27 11:20

    Chart have a "min" and "max" value. Documentation on this link

    https://www.chartjs.org/docs/latest/axes/cartesian/linear.html

    0 讨论(0)
  • 2020-11-27 11:25
    yAxes: [{
        display: true,
        ticks: {
            beginAtZero: true,
            steps:10,
            stepValue:5,
            max:100
        }
    }]
    
    0 讨论(0)
提交回复
热议问题