I am using chartjs.org 2.2.1 and have a radar chart that has values between 1..5. I want to set the min value to 0 and max to 5 with a step of 1.
This seemed to be answered exactly here in this SO post. However my charts still have a weird scale and not the one that I have defined as per my code below.
Can anyone see what I am doing wrong here?
var options = {
responsive: false,
maintainAspectRatio: true
};
var dataLiteracy = {
labels: [
@PointLabel("Literacy", 1), @PointLabel("Literacy", 2), @PointLabel("Literacy", 3),
@PointLabel("Literacy", 4), @PointLabel("Literacy", 5)
],
datasets: [
{
label: "Literacy",
backgroundColor: "rgba(179,181,198,0.2)",
borderColor: "rgba(179,181,198,1)",
pointBackgroundColor: "rgba(179,181,198,1)",
pointBorderColor: "#fff",
pointHoverBackgroundColor: "#fff",
pointHoverBorderColor: "rgba(179,181,198,1)",
data: [
@PointValue("Literacy", 1), @PointValue("Literacy", 2), @PointValue("Literacy", 3),
@PointValue("Literacy", 4), @PointValue("Literacy", 5)
]
}
]
};
var ctx = $("#chartLiteracy");
var myRadarChart = new Chart(ctx,
{
type: 'radar',
data: dataLiteracy,
options: options,
scaleOverride: true,
scaleSteps: 5,
scaleStepWidth: 1,
scaleStartValue: 0
});
You are right, but only if you are using Chart.js v1.x.
Ticks options have changed in v2.x (the one you are using).
ticks
attribute in your chart options :
var options = {
scale: {
ticks: {
// changes here
}
}
};
From what you need (mak a scale from 0 to 5), you can either :
beginAtZero
to true and max
to 5min
to 0 and max
to 5You can see here the result.
Set the value of stepSize
scale: {
ticks: {
beginAtZero: true,
max: 5,
min: 0,
stepSize: 1
}
}
Starting ChartJS 3 the min/max scale values are not specified in scale.ticks
but in options.scale
or options.scales[id]
object, example :
new Chart(hostElement, {
type: "radar",
data,
options: {
scale: {
min: 0,
max: 100,
},
},
});
https://www.chartjs.org/docs/latest/axes/radial/linear.html#linear-radial-axis :
scales.[x/y]Axes.ticks.max was renamed to scales[id].max
scales.[x/y]Axes.ticks.min was renamed to scales[id].min
https://codepen.io/JCH77/pen/abNymae
Only this schema worked for me on v3.8.0
options: {
maintainAspectRatio: false,
scales: {
r: {
min: 0,
max: 5,
beginAtZero: true,
angleLines: {
color: "red",
},
},
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With