Thank you for the response Paweł. I have been working with the example you posted and understand it well for a single time series. However my confusion comes to the proper formatting of multiple series.

I struggled in manipulating the data on the PHP side to get the data in the correct format:

    [time1, y1],
    [time2, y2],
    [time3, y3]
    [time1, z1],
    [time2, z2],
    [time3, z3]

However, after playing with things earlier today and ultimately drawing out a solution on a whiteboard I found a solution that appears to work, and required me to traverse the collected data arrays once for each series. It may not be optimal but works well for the few thousand points I tested it with. Here is my code for reference:

$seriesNames = array('Average Outdoor Temperature','Average Indoor Temperature');

foreach ($db->iterate($query) as $r) {
    $time = (float)$r->RecDateTime;
    $jstime = (float)($r->Timestamp*1000);
    $avgOutdoorTemperature = (float)$r->avgOutdoorTemperature;
    $avgIndoorTemperature = (float)$r->avgIndoorTemperature;

    $dataArray[] = array(array($jstime, $avgOutdoorTemperature), array($jstime, $avgIndoorTemperature));

$arraySize = sizeof($dataArray);
$seriesNameSize = sizeof($seriesNames);

for ($i=0; $i<$seriesNameSize; $i++) {
    $tempArray = array();
        for ($j=0; $j<$arraySize; $j++) {
            $tempArray[] = $dataArray[$j][$i];  
    $outputJSONArray[] = $tempArray;

echo json_encode($outputJSONArray);

I suppose I could have performed multiple queries and added each series manually, but the query I ultimately intend to use is fairly intensive and would prefer to call it only once.


Check Highcharts FAQ: Second example tells you how could this be done:

while ($row = mysql_fetch_array($result)) {
   extract $row;
   $datetime *= 1000; // convert from Unix timestamp to JavaScript time
   $data[] = "[$datetime, $value]";
var chart = new Highcharts.Chart({
      chart: {
         renderTo: 'container'
      series: [{
         data: [<?php echo join($data, ',') ?>]

Related Query

More Query from same tag