I’m using ChartJS 2.9.4 (restricted to V2 as generating PDFs using wkhtmltopdf) to build a line chart.
My problem is the data and I need to plot on the y axis.
Whilst the min/max ranges from 1-9 (with a 0.1 tick) it is impossible for some points within this range to be hit by the data and so I’d like to remove them and shift the other indexes down.
An example of the datapoints is:
1.1, 1.2, 1.3, 1.4, 1.5, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.1
In this example I need to remove the points between 1.5/2.1 so the latter follows on directly from the former. Is this even possible?
I have also tried leaving the y axis points as standard and just generating the labels at these points but they don’t display unless the conditions in the switch satisfy label % 5 === 0 e.g. case 1.0/case 1.5 will display a label but case 1.1 will not.
My testing table is below:
<div class="month-graph">
<canvas id="monthChart"></canvas>
</div>
new Chart(document.getElementById("monthChart").getContext('2d'), {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'August'],
datasets: [{
data: [1.8, 2.9, 3.6, 4.6, 5.6, 6.7, 7.7, 8.9],
fill: false,
borderColor: 'rgb(252, 210, 1)',
tension: 0
}]
},
options: {
scales: {
yAxes: [{
ticks: {
min: 1,
max: 9,
stepSize: 0.1,
callback: function(label, index, labels) {
switch(label) {
case 1.1:
return 'Level 1';
case 1.8:
return 'Level 2';
case 2.9:
return 'Level 3';
case 3.6:
return 'Level 4';
case 4.6:
return 'Level 5';
case 5.6:
return 'Level 6';
case 6.7:
return 'Level 7';
case 7.7:
return 'Level 8';
}
}
},
gridLines: {
color: '#c2c2c2'
}
}],
xAxes: [{
gridLines: {
color: '#c2c2c2'
}
}]
},
legend: {
display: false,
},
animation: false,
transitions: false
}
});