0

I'm making a line chart with Highcharts and data retrieve from mysql. This is my code:

<?php 

     $query = "select distinct idchip from datatable ";
     $result = mysql_query( $query );
     $rows = array();
     $count = 0;

     while( $row = mysql_fetch_array( $result ) ) {

         $table = array();

         $query2 = "select datetime,temperature from datatable where idchip=".$row['idchip'].' ';
         $query3 = "select datetime from datatable where idchip=".$row['idchip'].' group by datetime ASC';
         $timeresult = mysql_query($query3);

            while($datatime  = mysql_fetch_array($timeresult))
            {
                $newtime .= $datatime['0'].',';


                $newcates .= "'".$datatime['0']."',";
            } 

            $total= explode(",", $newtime);
            array_pop($total);
            $count = 0;

            $dataresult = mysql_query($query2);
            while($datarow = mysql_fetch_array($dataresult))
            {

                $data = '';
                //$datatimes = '';

                $datatimes .= $datarow['0'].',';

                //$stringtime .= $datatimes;


                $timetotal = explode(",",$datatimes);

                array_pop($timetotal);
                echo count($total).' |';

                //echo count($timetotal).' |';
                //echo $timetotal[$count]." |";
                $data .= (integer)$datarow['1'].',';
                $stringdata .= $data;

                }

        $newstring = $stringdata ;
        //$total = '';
        //$newtime = '';
        $stringdata = '';
        $stringtime = '';

        //$stringcates = '';
        //echo $newstring;
        $namedata = "{name:'Chip ".$row["idchip"]."',data:[$newstring]},";
        $getall .= $namedata;

     }

     $serries = 'series: [ '.$getall.' ]';
     $xAxis = 'xAxis: { categories:['.$newcates.']},';


?>

And this is what I want it to be show on chart, node data for chip 7 must be on "it must be here" location:

Example

So you guys saw that the data is not on it right point, because of data array is not in it location. So now I need to add some "null," to $newstring so i will have this string: null,null,[my data to show] -> these null node will help me to have data in right location. But i do everything i can and can't get something that help me to do this, please help me. i want to add some 'null,' to string when the time from YAxis is different from XAxis so data point will show correctly.

#

This is my database:

                id  idchip  datetime       signal temperature
Edit    Delete  1   5   2015-05-12 08:24:40     +   29
Edit    Delete  12  5   2015-05-12 08:23:40     +   031
Edit    Delete  3   6   2015-05-12 08:27:55     +   29
Edit    Delete  4   7   2015-05-12 08:26:01     +   50
Edit    Delete  5   5   2015-05-12 08:25:12     +   28
Edit    Delete  6   6   2015-05-12 08:28:32     +   29
Edit    Delete  7   6   2015-05-12 08:24:42     +   30
Edit    Delete  8   5   2015-05-12 08:27:58     +   29
Edit    Delete  9   5   2015-05-12 08:26:02     +   31
Edit    Delete  10  5   2015-05-12 08:26:13     +   29
Edit    Delete  11  5   2015-05-12 08:26:53     +   32
duong khang
  • 342
  • 1
  • 4
  • 19
  • How your data looks like? This point is included in you data anywhere or not? – Sebastian Bochan May 12 '15 at 12:10
  • @SebastianBochan updated my data. This point is included in mysql and retrieve from database. – duong khang May 12 '15 at 12:55
  • Why just don't you set specific index for that point? You have now: `[val, val, val]` for all series, so each value is connected to it's index in the categories array. How about this: `[ [index, val], [index, val], [index, val] ]` ? Where index is category index, for example "2015-05-12 08:26:53" -> index = 5. Or rather, why don't you use `datetime` axis? Then format will be: `[ [timestamp, val], [timestamp, val], [timestamp, val] ]` and remove categories. Of course timestamp should be in milliseconds. – Paweł Fus May 12 '15 at 16:17
  • @PawełFus i can't use datetime cause i need a "real time" chart so i must show all of data to the chart. i will try index but i think with huge data array it must be very slow to work with. – duong khang May 13 '15 at 02:34
  • It won't be slower. If you don't set indexes, then Highcharts will set them. And regarding "datetime" I don't understand? – Paweł Fus May 13 '15 at 10:32
  • @PawełFus i have done with this, you can help me in this link please. http://stackoverflow.com/questions/30208298/display-time-on-xaxis-with-line-chart-make-by-highcharts – duong khang May 13 '15 at 12:26

0 Answers0