我一直在尝试这个但看起来很难。我试图使y轴的数量取决于用户选择。有3个部分供用户选择,即:
如果用户选择2 ID和2 Field,那么我应该在图上有4条不同的线。这意味着:
行数=所选ID数*所选字段数
据我所知,我将为图例中的标签以及要显示的y轴的数量获得相同的编号。
对于我给出的例子,它应该是这样的:
用于图例标签和要生成的y轴,但这一切都取决于用户选择。
感谢您的关注。
答案 0 :(得分:0)
我终于找到了一种解决方法,通过从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函数中,我将系列设置为Label:
series:Label