score:0
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.
score:1
Check Highcharts FAQ: http://docs.highcharts.com/#preprocessing-data-from-a-database Second example tells you how could this be done:
<?php
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, ',') ?>]
}]
});
Source: stackoverflow.com
Related Query
- Formatting PHP/MySQL data in correct JSON format for HighCharts
- Formatting JSON data monthwise for HighCharts using MySQL
- Formatting data in correct format for HighCharts mvc asp.net
- how to create proper json data format from mysql for highcharts
- Highcharts PHP JSON - correct data format
- Formatting JSON Data with ColdFusion for HighCharts
- How to format my json data for stack column chart in HighCharts
- Formatting JSON from a Pandas data frame for Highcharts within a Django template
- How to create data in Json format for highcharts
- JSON Data formatting for Highcharts
- How do I get DateTime from mysql and set it to json format ready for highcharts
- YQL finance data JSON format for use with highcharts
- Highcharts format json data from php script / unixtime
- Highcharts JSON formatting - splitting up and preprocessing data for charts?
- How to format Highcharts columnRange to get json data for temperature Min and Max
- Format Highcharts xAxis for stock data
- Highcharts Mysql Json arrays PHP
- Highcharts Mysql Json arrays PHP
- How to format datetime for (x,y) pair data for Highcharts
- Write JSON parser to format data for pie chart (HighCharts)
- Parsing JSON data for Highcharts
- Highchart - Display JSON Data - MYSQL / PHP
- Highcharts JSON decimal data format issue
- Retrieving JSON data for Highcharts with multiple series?
- JSON data not showing in highstock Candlestick chart using PHP & MYSQL
- Extracting data from a JSON call to a Postgres table for use in Highcharts (without PHP)
- Getting data from Postgres in JSON format in ROR into a Highcharts javascript
- passing formatting JavaScript code to HighCharts with JSON
- Formatting data array correctly for Highcharts
- Format data for highcharts solid gauge graph
More Query from same tag
- Can you remove specific grid lines and point labels using highcharts without css?
- How to reduce the area around a highcart?
- How to append highcharts on same div?
- Adding series dynamically in highcharts
- Highstock panning asynchronously loading data
- hightchart : centered value and arrow
- Column chart overlaps to one line when there's just a group of data
- How to draw on charts?
- Can i add two axis in a spiderweb highcharts and click x-axis label navigate to another page?
- Image not exporting correctly in highcharts
- LINQ that groups data and returns series for chart
- Highcharts / HighStock gapUnit breaks navigator
- Display Highcharts data from mysql database on jsp page
- Highcharts: multiple charts and one update function
- Invalid temp images directory in chart handler configuration
- How to change height and tooltip width for JS library highcharts?
- High Charts Range Selector
- Can not deploy a chart file from spagobi studio
- Draw svg file on highchart or inside html tag
- HighCharts not being displayed in Partial view
- How to add vertical (and horizontal) line in highcharts scatter plot
- HighChart Libraries for Android and IOS
- Remove the categories text under the bars on Highcharts chart
- Highcharts: Second series won't plot on second axis
- Build a highchart chart using data from an external JSON
- How to achieve the best possible performance with mutable data and real-time charts in React?
- Highcharts : Show ticker on the start of plot
- cURL not fetching the expected POST response - error 405
- showing ranks on yaxis in highchart in a manner that 1 is best and 50 is worst
- How to set reset zoom button and title to exactly center of the high charts