I'm currently working to retrieve some data for which I want to use a FLOT line chart.
At present, this is how I am creating the array by getting data from the MYSQL database:
$data = array("label" => $title);
while($row = $query->fetch()) {
$data['data'][] = array($row[3], $row[2]);
}
$json = json_encode($data, JSON_NUMERIC_CHECK);
echo $json;
The above code output the following array (Based on the data from the Database):
{"label":"hosting","data":[[2,"06\/07\/2014"],[7,"09\/07\/2014"]]}
This is what I want, however I need to somehow change the formatting of the array so that it is correctly formatted for the FLOT charts.
How would I got about changing the array from this:
{"label":"hosting","data":[[2,"09\/07\/2014"],[2,"09\/07\/2014"]]}
To this:
{label: 'hosting', data: [[2,09\/07\/2014], [2,09\/07\/2014]]}
Using JQuery try this,
<script type="text/javascript">
var obj = jQuery.parseJSON ( ' + <?php echo $json; ?> + ' );
</script>
try doing this
$data = array(label => $title, data => array());
while($row = $query->fetch()) {
$data[data][] = array($row[3], $row[2]);
}
instead
$data = array("label" => $title);
while($row = $query->fetch()) {
$data['data'][] = array($row[3], $row[2]);
}