3

I checked several posts. However none of the solution solved my issue.

It's a quite standard usage of min and max. I use the same setting in Barchart and it worked. not working in line chart on the same page.

I tried with suggestedMax, suggestedMin as well.

By the way, my dataset has multiple line series.

version 2.1.6

var ctx = document.getElementById(canvas);
   var lineChart = new Chart(ctx, {
    type: 'line',
    data: lineChartData,

    option: {
        scales: {
        yAxes: [ {
//              type: 'linear',
            ticks: {
                beginAtZero: true,
                max : 50,
                min : 0,

                }
            } ]
        }
    }

Then I tried a piece of code from another post...not working....

var data = {
 labels: ["January", "February", "March", "April", "May", "June", "July"],
 datasets: [
    {
        label: "Test dataset",
        fill: false,
        data: [65, 59, 80, 81, 56, 55, 40],
    }
]
};
var ctx = document.getElementById("testLineChart");
    var myLineChart = new Chart(ctx, {
        type: 'line',
        data: data,
        option: {
            scales: {
            yAxes: [ {
                type: 'linear',
                ticks: {
                    beginAtZero: true,
                    min : 0,
                    max : 100,
                    }
                } ]
            }
        }
    });
Qi Yu
  • 31
  • 1
  • 5

1 Answers1

1

You have to use lowercase, to match Chartjs object attribute for min and max. Using the first letter as uppercase, you are creating a new field in the object, which is not parsed by Chartjs.

Try changing your code to:

ticks: {
            beginAtZero: true,
            max : 50,
            min : 0,
       }

UPDATE:

When creating a chart, the options attribute should be plural (options instead of option), you are missing an S in the word.

The correct way is:

var myLineChart = new Chart(ctx, {
    type: 'line',
    data: data,
    options: { ... }
}
Miguel Péres
  • 630
  • 1
  • 10
  • 19
  • Oh... It's actually lower case in my code...however, not working. – Qi Yu Jun 25 '16 at 16:10
  • @QiYu I've copied and pasted your **options** into my code, and it worked in my line charts (that also has multiple lines). Take a look at this screenshot I took, [here](http://i.imgur.com/ARL0PMW.png). What exactly is happening? The chart just ignore the min and max settings and auto scale? – Miguel Péres Jun 28 '16 at 19:13
  • Please find the code I tested in my post...it's not working on my page.... – Qi Yu Jun 30 '16 at 14:34
  • I think I figured it out. When creating the chart, the options attribute should be called `options` **(plural)**, not `option`. I will edit my answer, so it's easy to find the solution. – Miguel Péres Jul 04 '16 at 13:28