Now, when you say that, it sounds obvious.
For some reason, the number 0 does not appear in my bar graph (it starts at 1 on the y-axes), even though I typed 'beginAtZero: true'.
This is a bit annoying then, it is sometimes only value 1.
Here's the code:
<?php
$data = '';
$label = '';
$colorCode = '';
//loop through the returned data
while (!$rsCount->atEnd()) {
$data = $data . '"'. $rsCount->getColumnVal("countEachCategory").'",';
$label = $label . '"'. $rsCount->getColumnVal("categoryName").'",';
$colorCode = $colorCode . '"'. $rsCount->getColumnVal("colorcode").'",';
$rsCount->moveNext();
}
$data = trim($data,",");
$label = trim($label,",");
$colorCode = trim($colorCode,",");
?>
----
<script>
let labels = [<?php echo $label; ?>]
let data = [<?php echo $data; ?>];
let colors = [<?php echo $colorCode; ?>];
var ctx = document.getElementById("chart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets:
[{
label: '',
data: data,
backgroundColor: colors,
}]
},
options: {
scales: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}],
}
},
tooltips: {
mode: 'index'
},
legend: {
display: false
}
}
});
</script>