用户在jqplot中指定要绘制的y轴数

时间:2022-10-18 20:45:40

Please I have been trying this but seems difficult. I am trying to make the number of y-axis depend on the user selection. There are 3 sections for user to select from, namely:

我一直在尝试这个,但似乎很难。我试图使y轴的数量取决于用户选择。有3个部分供用户选择,即:

  1. Time range for the plot
  2. 情节的时间范围

  3. ID to plot, which will be taken from database
  4. 要绘制的ID,将从数据库中获取

  5. Field to search in the database
  6. 要在数据库中搜索的字段

If the user selects 2 ID and 2 Field, then I should have 4 different lines on the plot. Which means that:

如果用户选择2 ID和2 Field,那么我应该在图上有4条不同的线。意思就是:

number of lines = number of ID selected * number of Field selected

行数=所选ID数*所选字段数

With that I know I will get same number for the labels in the legend and also for the number of y-axis to be displayed.

据我所知,我将为图例中的标签以及要显示的y轴的数量获得相同的编号。

For the example I gave, it should be something like:

对于我给出的例子,它应该是这样的:

  • Field_1-ID_1
  • Field_2-ID_1
  • Field_1-ID_2
  • Field_2-ID_2

for the legend label and the y-axis to be produced, but it all depends on the user selection.

对于图例标签和要生成的y轴,但这一切都取决于用户选择。

Thank you for your attention.

感谢您的关注。

1 个解决方案

#1


0  

I finally found a way to resolve this by generating from the php side, the elements for the series property in the jqplot in its expected format i.e.

我终于找到了一种解决方法,通过从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'}]

If anyone is interested in how it is done, please check the code below:

如果有人对如何完成感兴趣,请检查以下代码:

$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 "];";

The output of that php is like:

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'}];

Then in the jqplot function, I set series to be Label:

然后在jqplot函数中,我将系列设置为Label:

series:Label

#1


0  

I finally found a way to resolve this by generating from the php side, the elements for the series property in the jqplot in its expected format i.e.

我终于找到了一种解决方法,通过从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'}]

If anyone is interested in how it is done, please check the code below:

如果有人对如何完成感兴趣,请检查以下代码:

$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 "];";

The output of that php is like:

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'}];

Then in the jqplot function, I set series to be Label:

然后在jqplot函数中,我将系列设置为Label:

series:Label