0👍
Your data is set to json_encode, this is not how chart.js can read it.
Change your code from:
<?php=json_encode($count);?>
To:
["<?php echo implode('","',$count);?>"]
And for the years, from:
<?php=json_encode($years);?>
to:
["<?php echo implode('","',$years);?>"]
The quotes are there to contain anything the isn’t a numerical value, if your positive that all data is numerical, you can remove them, but since it doesn’t hurt to have them, I’ve included them.
- Chartjs-Testing Chart.js Plugin with React and Jest/Enzyme
- Chartjs-Need Clarity on Chartjs – Asp.NetMVC or Vue-ChartJS -Asp.Net MVC
0👍
Figured this out:
1: Used this query:
SELECT YEAR(purchased) as years, COUNT(ID) as count FROM computers GROUP BY years
2: Had a TYPO! while ($row = mysql_fetch_assoc($result)) should had been:
while ($row = mysqli_fetch_assoc($result)). I forgot the i in mysql_fetch!
Along with the great help from Greg it is working great now.
Thanks for the help!
- Chartjs-Setting Canvas Limits Over the Existing Dataset Values
- Chartjs-Set Chart Background Image – Chart.js
Source:stackexchange.com