Reputation: 85
I am using chart.js chart on my web page and I need to specify the min and max value of the chart axis. I can easily use the code shown below to specify the minimum and maximum value of the x axis of the chart but...
options: {
scales: {
xAxes: [{
ticks: {
max: 100,
min: 0,
But, I need to have different minimum and maximum value depending on the value of the javascript variable 'Subject'.
So, I need to have the code such as:
options: {
scales: {
xAxes: [{
ticks: {
if(Subject == 'English'){
return "max: 100,";
} else {
return "max: 50,";
}
min: 0
But this code shows "token not valid" error message. How can I correctly insert conditional statement within the javascript option specification area?
Upvotes: 1
Views: 2322
Reputation: 1
You can write the if statement outside the option, this worked for me:
if(Subject == 'English'){
max1= 100;
} else {
max1= 50;
}
And then:
options: {
scales: {
xAxes: [{
ticks: {
max: max1,
min: 0,
Upvotes: 0