When I pass the array as an argument to the chart it stops showing on the web page.
<?php
$f = fopen("C:\wamp64\www\dashb\CSV\salespermonthdollars.csv", "r");
$labels = array();
$data = array();
$loopCounter = 0;
while (($line = fgetcsv($f)) !== false) {
if($loopCounter == 0){
// this if is to skip the first row or the columns
} else {
array_push($labels,$line[0]);
array_push($data,$line[1]);
}
$loopCounter = $loopCounter + 1;
}
fclose($f);
?>
So above I read the csv file that I save from my query result and try to plot it on a chart:
<canvas id="myChart2">
<script>
$array3 = [1,2,3,4,5,5,41];
$array4 = [1,2,3,4,5,5,41];
var ctx = document.getElementById('myChart2').getContext('2d');
var myBarChart = new Chart(ctx, {
type: 'bar',
data: {
labels: $array3, //when i change this to $labels doesn't work same for4
datasets: [{
label: 'label',
data: $array4,
backgroundColor: "rgba(100,255,51,0.4)"
}]
}
});
</script>
</canvas>
Mainly I am displaying query result on a chart. I execute, save to csv and read
from there.
Any suggestions for improvement in the approach are welcome, somehow I feel it could be done easier than this.