score:76
You have to overrride the scale, try this: (applies to ChartJS v1.x)
window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx).Line(lineChartData, {
scaleOverride : true,
scaleSteps : 10,
scaleStepWidth : 50,
scaleStartValue : 0
});
}
score:-1
yes you can set it to min
and max
range
options: {
resposive: true,
title: {
display: true
},
hover: {
mode: 'index',
intersect: true
},
scales: {
y: {
suggestedMin: 0,
suggestedMax: 500
}
}
}
score:1
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,
[...]
score:2
With 1.1.1, I used the following to fix the scale between 0.0 and 1.0:
var options = {
scaleOverride: true,
scaleStartValue: 0,
scaleSteps: 10,
scaleStepWidth: 0.1
}
score:3
v3.X (v3.5.0)
Linear Cartesian Axis
let options = {
scales: {
y: {
beginAtZero: true,
suggestedMax: 69
},
x: {
beginAtZero: true,
suggestedMax: 420
},
ticks: {
stepSize: 1
}
}
}
Ref. https://www.chartjs.org/docs/3.5.0/axes/cartesian/linear.html
Linear Radial Axes
let options = {
scales: {
r: {
beginAtZero: true,
suggestedMax: 5,
ticks: {
stepSize: 1
}
}
}
}
Ref. https://www.chartjs.org/docs/3.5.0/axes/radial/linear.html
v2.X (v2.9.4)
Linear Cartesian Axis
let options = {
scale: {
ticks: {
beginAtZero: true,
stepSize: 1,
suggestedMax: 5,
}
}
}
Ref. https://www.chartjs.org/docs/2.9.4/axes/cartesian/linear.html
Linear Radial Axes
let options = {
scale: {
ticks: {
beginAtZero: true,
stepSize: 1,
suggestedMax: 5,
}
}
}
Ref. https://www.chartjs.org/docs/2.9.4/axes/radial/linear.html
Note: scale in singular in v2 and plural in v3
score:4
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.)
score:6
This is for Charts.js 2.0:
The reason some of these are not working is because you should declare your options when you create your chart like so:
$(function () {
var ctxLine = document.getElementById("myLineChart");
var myLineChart = new Chart(ctxLine, {
type: 'line',
data: dataLine,
options: {
scales: {
yAxes: [{
ticks: {
min: 0,
beginAtZero: true
}
}]
}
}
});
})
Documentation for this is here: http://www.chartjs.org/docs/#scales
score:6
In my case, I used a callback in yaxis ticks, my values are in percent and when it reaches 100% it doesn't show the dot, I used this :
yAxes: [{
ticks: {
beginAtZero: true,
steps: 10,
stepValue: 5,
min: 0,
max: 100.1,
callback: function(value, index, values) {
if (value !== 100.1) {
return values[index]
}
}
}
}],
And it worked well.
score:8
Just set the value for scaleStartValue in your options.
var options = {
// ....
scaleStartValue: 0,
}
See the documentation for this here.
score:8
yAxes: [{
display: true,
ticks: {
beginAtZero: true,
steps:10,
stepValue:5,
max:100
}
}]
score:9
> Best Solution
"options":{
scales: {
yAxes: [{
display: true,
ticks: {
suggestedMin: 0, //min
suggestedMax: 100 //max
}
}]
}
}
score:11
For "chart.js": "^3.6.1",
options: {
scales: {
y: {
min: 0,
max: 100,
}
}
}
score:13
For Chart.js v3.2.0, do this:
let options = {
scales: {
y: {
suggestedMin: 0,
suggestedMax: 69
},
x: {
suggestedMin: 0,
suggestedMax: 420
}
}
}
Documentation: https://www.chartjs.org/docs/latest/axes/#axis-range-settings
score:14
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
score:16
window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx ,{
type: 'line',
data: yourData,
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true,
min: 0,
max: 500
}
}]
}
}
});
I configure with 'options' in v2.
You should read documentation: http://www.chartjs.org/docs/#scales-linear-scale
score:16
I wrote a js to display values from 0 to 100 in y-axis with a gap of 20.
This is my script.js
//x-axis
var vehicles = ["Trucks", "Cars", "Bikes", "Jeeps"];
//The percentage of vehicles of each type
var percentage = [41, 76, 29, 50];
var ctx = document.getElementById("barChart");
var lineChart = new Chart(ctx, {
type: 'bar',
data: {
labels: vehicles,
datasets: [{
data: percentage,
label: "Percentage of vehicles",
backgroundColor: "#3e95cd",
fill: false
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
min: 0,
max: 100,
stepSize: 20,
}
}]
}
}
});
This is the graph displayed on the web.
score:47
ChartJS v2.4.0
As shown in the examples at https://github.com/jtblin/angular-chart.js on the 7th of febuary 2017 (since this seems to be subject to frequent change):
var options = {
yAxes: [{
ticks: {
min: 0,
max: 100,
stepSize: 20
}
}]
}
This will result in 5 y-axis values as such:
100
80
60
40
20
0
score:53
As of Feb 2022, this works. Here is how one can change it
var options = {
scales: {
yAxes: [{
display: true,
stacked: true,
ticks: {
min: 0, // minimum value
max: 10 // maximum value
}
}]
}
};
score:78
var config = {
type: 'line',
data: {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "My First dataset",
data: [10, 80, 56, 60, 6, 45, 15],
fill: false,
backgroundColor: "#eebcde ",
borderColor: "#eebcde",
borderCapStyle: 'butt',
borderDash: [5, 5],
}]
},
options: {
responsive: true,
legend: {
position: 'bottom',
},
hover: {
mode: 'label'
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Month'
}
}],
yAxes: [{
display: true,
ticks: {
beginAtZero: true,
steps: 10,
stepValue: 5,
max: 100
}
}]
},
title: {
display: true,
text: 'Chart.js Line Chart - Legend'
}
}
};
var ctx = document.getElementById("canvas").getContext("2d");
new Chart(ctx, config);
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.2.1/Chart.bundle.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<canvas id="canvas"></canvas>
</body>
score:328
For chart.js V2 (beta), use:
var options = {
scales: {
yAxes: [{
display: true,
ticks: {
suggestedMin: 0, // minimum will be 0, unless there is a lower value.
// OR //
beginAtZero: true // minimum value will be 0.
}
}]
}
};
See chart.js documentation on linear axes configuration for more details.
Source: stackoverflow.com
Related Query
- How to set max and min value for Y axis
- How to set min max for x axis depend on data with Chartjs and Spring Boot?
- ChartJS: How to set fixed Y axis max and min
- How to set the xAxes min and max values of time cartesian chart in Chart.js
- How to set y axis to the max dataset value in Chartjs?
- How do you set x and y axis and Title for a line chart using charts.js?
- chart.js how to force min and max y axis values
- How to set min Value a step down of min value received from database in Y Axis in ChartJS
- How to set only min and max values in y-axis (chart js)
- Chart.js timescale: set min and max on xAxes
- Hide min and max values from y Axis in Chart.js
- ng2-charts: How to set fixed range for y axis
- Chart.js - Setting max Y axis value and keeping steps correct
- Chartjs: how to show only max and min values on y-axis
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- how to change Y axis value dynamically based on user input in Chartjs for Line chart?
- ChartJS How to set max labels for X axis?
- How do I force Chart.js axes min and max with react-chartjs-2?
- How to set lower limit for the highest value being displayed on Y Axis?
- In Chart.js >3.0, on axis of type time, how to show labels and ticks only for existing data points (make labels reflect data)?
- How to show scale labels and set min/max for yAxes?
- How do I customize y-axis labels and randomly pick the value from the data range for x-axis in Chart js
- How to set max smaller than min in ChartJS
- How to change fonts and axis labels for Chart.js image rendering with QuickChart?
- How to set dynamic value for horizontal line in annotation plugin for Chart.js
- How to give link for lable/Legend in chart.js? and if the value is 0 how to remove the legend?
- How to set and adjust plots with equal axis aspect ratios - CHART.js
- Chart.js - Same min and max value of two charts
- How to set 3 axis in google chart (V-Axis Left as Qty, V-Axis Right as Series Column and H-Axis as TimeOrder)?
- ChartJs: x-axes min and max value not working
More Query from same tag
- how to modify and make labels box width fixed without changes of chart.js
- Chart JS can't access data from array within an object
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- Chartjs how to show scale label horizontally
- Chart.js — drawing an arbitrary vertical line
- Why the bar are not aligned the y axis
- Chartjs time plot xAxis shows year 1970
- How to pass a dictionary to ChartJS?
- I can't add data to chartjs from codeigniter
- Fill color to pointer in Chartjs
- How to grouping Label In Char JS
- first and last value is not displaying in chart.js used with django
- give values to Chartjs
- How to order tooltip values from the biggest to the smallest
- How can I rotate a pie chart in charts.js?
- How to change the angle of x axis ticks dynamically based on size of name?
- Updating Chart Data on Charts.js with Ng2-Charts
- How to use php variables in a chart js chart
- Why is chart.js not working with angular JS
- Chart.JS Time Axis Not Parsing
- Using ticks 'major' with Chart.js is overlapping with an unknown text
- How to show data values or index labels in ChartJs (Latest Version)
- Cannot get Chart.js working
- Chart.js maxBarThickness option not working
- Chartisan/Laravel - > "Call to undefined method" error
- Looping through json array properties
- How to install Chart.js and angular-chart.js (Error: Chart.js library needs to be included)
- Chart JS 2.x: How to show a tooltip in a timeline chart?
- Chart.JS - Fill Donut
- Snapshot testing ChartJS components with Jest