I have an Array $array
and want to create an html5 chart using the values of that array. For that purpose I use chart.js
The code I use looks like this (Unfortunately, I need to output the Javascript via PHP):
$chart = '
<script>
var data = {
labels: ['."$array[0]".', '."$array[1]".', "..."],
datasets: [
{
label: "My Chart",
fillColor: "rgba(220,220,220,0.5)",
strokeColor: "rgba(220,220,220,0.8)",
highlightFill: "rgba(220,220,220,0.75)",
highlightStroke: "rgba(220,220,220,1)",
data: [65, 59, 80, 81, 56, 55, 40]
}
]
};
</script>';
print_r($chart);
That works fine so far, but the array gets updated with time to time and so should the chart. I figured out I would need a loop to do that but am not quite sure how to run the loop in the Javascript code. This doesnt work:
labels: ['.for ($i = 0, $i < count($array), $i++) {echo "$array[$i].','"}.'];