UPDATE I have updated my code in response to @MichaelRushton comments. I am now using Highcharts but I am having trouble getting output to the data series.
I now have the following array generated from a mysql query, and I would like to output it into a line chart. My Y-Axis should contain the amount, x-axis is the date range, and legend is the different items plotted on the chart.
// Call the stored procedure
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$array[$row['legend']][$row['date']] = $row['amount'];
//print_r($array);
}
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'line'
},
xAxis:
{
categories: [2012-03-01, 2012-03-02, 2012-03-03, 2012-03-04, 2012-03-05, 2012-03-06, 2012-03-07, 2012-03-08, 2012-03-09, 2012-03-10, 2012-03-11, 2012-03-12, 2012-03-13, 2012-03-14, 2012-03-15, 2012-03-16, 2012-03-17, 2012-03-18, 2012-03-19, 2012-03-20, 2012-03-21, 2012-03-22, 2012-03-23, 2012-03-24, 2012-03-25, 2012-03-26, 2012-03-27, 2012-03-28, 2012-03-29, 2012-03-30, 2012-03-31],
},
series:
[
<?php
foreach ($array as $legend => $data)
{
echo '{';
echo "name: '" . $legend . "',";
$values = array();
for ($i = 1; $i <= 31; ++$i)
{
$values[] = isset($data[$i]) ? $data[$i] : 0;
}
echo 'data: [' . implode(', ', $values) . '],';
echo '},';
}
?>
],
}
);
<div id="container" style="width: 100%; height: 400px"></div>
)
This code is presenting me with the following output:
series: [ {name: 'Something Tastier',data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],},{name: 'Something Tasty',data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],}, ], } );
The seems right except there is no values outputting to the data series. If anyone has any further ideas it would be much appreciated.