我终于找到了一种方法来解决这个问题,方法是从 php 端生成 jqplot 中系列属性的元素,以预期的格式,即
series:[{label:Field_1-ID_1,yaxis:'yaxis'},{label:Field_1-ID_2,yaxis:'y2axis'},{label:Field_2-ID_1,yaxis:'y3axis'},{label:Field_2-ID_2,yaxis:'y4axis'}]
如果有人对它的完成方式感兴趣,请检查以下代码:
$con = mysql_connect($hostname, $username, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database, $con);
$unit = mysql_real_escape_string($_GET["units"]);//ID selected by user, e.g.(ID_1,ID_2)
$stat = mysql_real_escape_string($_GET["start"]);//start time
$stop = mysql_real_escape_string($_GET["stop"]);//stop time
$field1 = mysql_real_escape_string($_GET["fieldlist"]);//Field selected by user, e.g.(Field_1,Field_2)
$first=true;
echo "Label=";
echo "[";
$field = explode(",", $field1);
$count=count($field);
$i=0;$j=1;
while($i<$count)
{
$sq="SELECT su_id FROM Station_stat
WHERE su_id in ($unit) GROUP BY su_id";
$res = mysql_query($sq);
while($row = mysql_fetch_array($res)){
if ($first != true )
{
echo ",";
echo "{label:\"$field[$i] ".$row['su_id']."\",yaxis:\"y".++$j."axis\"}";
}
else
echo "{label:\"$field[$i] ".$row['su_id']."\",yaxis:\"yaxis\"}";
$first = false;
}
++$i;
}
echo "];";
该php的输出如下:
Label=[{label:Field_1-ID_1,yaxis:'yaxis'},{label:Field_1-ID_2,yaxis:'y2axis'},{label:Field_2-ID_1,yaxis:'y3axis'},{label:Field_2-ID_2,yaxis:'y4axis'}];
然后在 jqplot 函数中,我将系列设置为标签:
series:Label