javascript - Highcharts add point to line chart with json -


i need add point data mysql database. @ time, data json don't know why in output array, data have double quote(" ") this:

["{name:'chip 3',data:[[moment('2015-05-14 13:26:21','hh:mm:ss').valueof(),29],[moment('2015-05-14 13 :26:51','hh:mm:ss').valueof(),29],[moment('2015-05-14 13:27:21','hh:mm:ss').valueof(),29],[moment('2015-05-14  13:27:51','hh:mm:ss').valueof(),29],[moment('2015-05-14 13:28:21','hh:mm:ss').valueof(),29],[moment('2015-05-14  14:42:54','hh:mm:ss').valueof(),32],]}"] 

so highcharts can not access data , show data on chart. need remove double quote array or else make highcharts can regconize data.

this code in data.php file use , update series data.

<?php  header("content-type: text/json");    include_once 'include/connection.php';  $db = new db_class();          $query = "select distinct idchip datatable ";      $result = mysql_query( $query );      $rows = array();      $count = 0;      $getall = array();      while( $row = mysql_fetch_array( $result ) ) {           $table = array();           $query2 = "select datetime,temperature datatable idchip=".$row['idchip'].' group datetime ';              $dataresult = mysql_query($query2);             while($datarow = mysql_fetch_array($dataresult))             {                  $data = '';                   $datatimes .= $datarow['0'].',';                   $data .= "[moment('".$datarow['0']."','hh:mm:ss').valueof(),".(integer)$datarow['1']."],";                 $stringdata .= $data;                  }          $newstring = $stringdata ;          $stringdata = '';         $stringtime = '';          $namedata = "{name:'chip ".$row["idchip"]."',data:[$newstring]}";         $getall[] = $namedata;        }   echo json_encode($getall); ?> 

this code use ajax return data.

function getdata() {         jquery.ajax({             url: 'data.php',             type: 'get',             datatype: 'json',             mimetype: 'multipart/form-data',             contenttype: false,             cache: false,             processdata: false,             success: function( data, jqxhr ) {                 if( data == "null" ) {                  } else {                   $.getjson("data.php", function(json) {              chart = new highcharts.chart({                chart: {                 renderto: 'container',                 defaultseriestype: 'spline',                 events: {                //     load: requestdata                 }             },  series: json              });         });                 }             },             error: function( textstatus ) {                 console.log(" error. damm. ");                 //console.log(error);             }         });     }  

i think this

    $query = "select distinct idchip datatable ";     $result = mysql_query( $query );     $rows = array();     $count = 0;     $getall = array();     while( $row = mysql_fetch_array( $result ) ) {          $table = array();         $stringdata = array();         $query2 = "select datetime,temperature datatable idchip=".$row['idchip'].' group datetime ';          $dataresult = mysql_query($query2);          $stringdata = array();         while($datarow = mysql_fetch_array($dataresult))         {             $stringdata[] = "moment('".$datarow['0']."','hh:mm:ss').valueof(),".(integer)$datarow['1'];         }          $namedata['name'] = "chip ".$row["idchip"];         $namedata['data'] =  $stringdata;         $getall[] = $namedata;     }      echo json_encode($getall); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -