So I have a PHP array created from data pulled from Advanced Custom Fields in WordPress:
<?php
$chartArray = array();
forEach($cat_meta as $key => $value) {
$chartArray[] = array($value['star_rating']);
}
echo json_encode($chartArray);
?>
This outputs the following on the page:
[["2"],["4"],["1"],["3"],["5"]]
What I'm trying to do is get that result into the data variable of the ChartJS file:
var radarChartData = {
labels: ["Price", "Speed", "Format", "Size", "User Experience"],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(224,07,19,1)",
pointColor: "rgba(224,07,19,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(224,07,19,1)",
data: [5, 4, 5, 5, 1, 3] // data needs to replace this
}
]
};
var ctx = document.getElementById('RadarChart').getContext('2d');
var myRadarChart = new Chart(ctx).Radar(radarChartData);
I am a bit of a PHP / Javascript n00b so I'm hoping someone might be able to shed some light on this for me. Or maybe there is a better way of doing this? Thank you in advance.