我正在制作一个包含Highcharts的折线图,并从mysql中检索数据。这是我的代码:
<?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.']},';
?>
这就是我希望它在图表上显示,芯片7的节点数据必须在“它必须在这里”位置:
所以你们看到数据不正确点,因为数据阵列不在它的位置。所以现在我需要在$ newstring中添加一些“null”,这样我就会有这个字符串:null,null,[我的数据显示] - &gt;这些空节点将帮助我将数据放在正确的位置。但我尽我所能,无法得到帮助我做到这一点,请帮助我。我希望在YAxis的时间与XAxis不同时为字符串添加一些'null',这样数据点就能正确显示。
#这是我的数据库:
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