dongzanxun2790 2018-05-13 18:45
浏览 102
已采纳

如何通过HTML表单和下拉菜单动态更改dygraphs的URL

I would really appreciate if someone could help me out. I did try hard to find a solution but to no avail due to my limited skills. Here is the scenario: I have got a python script that outputs temperature, pressure and humidity from a sensor connected to my Raspberry Pi. The same script also saves the readings into a .CSV file which has the date as file name so that I have every day a unique file with a full day's worth of data in it. I have implemented within a PHP page an open source JavaScript charting library in order to plot the readings:

link to dygraphs.com library

Also within the same PHP page I can select from a drop down menu the .CSV files mentioned above. To achieve that I have used the foreach construct.

Anyway please see below my PHP code:

<html>
<center>
   <iframe width="800" height="600"  src="http://SERVER_IP_ADDRESS/graphs.php" frameborder="0" allowfullscreen="" scrolling="no$
</center>
<head>
<script type="text/javascript"
<script src="//cdnjs.cloudflare.com/ajax/libs/dygraph/2.1.0/dygraph.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/dygraph/2.1.0/dygraph.css" />
</head>
<body>
<div id="graphdiv2"
  style="width:700px; height:500px;"></div>
<script type="text/javascript">
  g2 = new Dygraph(
    document.getElementById("graphdiv2"),
     "20180508.csv", // path to CSV file
    {rollPeriod: 7,
      showRoller: true}                   // options
  );
</script>
</body>
</html>
</head>

<body>
<?php
$filename = 'CSV_index.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);
?>
<form method="post" action="">
        <select name="menu">
            <option selected value="base">Please Select</option>
           <?php foreach($eachlines as $lines){ //add php code here
                echo "<option value='".$lines."'>$lines</option>";
            }?>
        </select>

 <button type="submit" name="submit" >Submit</button>

 </form>

<?php
if(isset($_POST["submit"]))
{

$selected_value=$_POST["menu"];

?>

Now this is what I would love to achieve: once I select the .CSV file from the drop down menu, I would like it to appear automatically in the line below:

"20180508.csv", // path to CSV file

This is where the library finds the path to the .CSV file to plot that graph. So by selecting a specific .CSV I can then plot the relevant graph for a specific day.

I have tried the following but of course both didn't work:

"$selected_value", // path to CSV file

"'$selected_value'", // path to CSV file

Many thanks in advance for your kind kelp.

  • 写回答

1条回答 默认 最新

  • douli6605 2018-05-24 10:49
    关注

    SOLVED! After a lot of readings I have managed to solve my issue. The code below did the trick:

    <?php
    'echo $selected_value;'
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,