Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng2-charts: How to set fixed range for y axis

I have a chart.js chart using ng2-charts module. The chart shows Percentage on y axis and time on x axis. Is it possible to set y axis to show 0 to 100 instead of dynamic range based on data?

like image 441
user2347528 Avatar asked Aug 21 '18 14:08

user2347528


2 Answers

Try adding the following to your chart options:

scales : {
  yAxes: [{
     ticks: {
        steps : 10,
        stepValue : 10,
        max : 100,
        min: 0
      }
  }]
}

https://github.com/valor-software/ng2-charts/issues/853

like image 142
Cookie Avatar answered Oct 20 '22 03:10

Cookie


In my name.component.html:

<div style="display: block">
<canvas baseChart height="100" [datasets]="lineChartData" [labels]="lineChartLabels" [options]="lineChartOptions"
    [colors]="lineChartColors" [legend]="lineChartLegend" [chartType]="lineChartType"></canvas>

In my name.component.ts:

 public lineChartOptions: any = {
    scales : {
        yAxes: [{
            ticks: {
            beginAtZero: true,
                stepValue: 10,
                steps: 20,
              max : 50,
            }
        }]
      }
};
like image 4
Sabin Bogati Avatar answered Oct 20 '22 04:10

Sabin Bogati