Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript php代码var anidade中的Post请求_Javascript_Php_Charts - Fatal编程技术网

Javascript php代码var anidade中的Post请求

Javascript php代码var anidade中的Post请求,javascript,php,charts,Javascript,Php,Charts,我正在使用动态图绘制Arduino传感器数据。我需要在两个数据之间进行减法,所以我在脚本函数中使用php,但它不起作用。可以包括 <script type="text/javascript"> var csv = [ '<?php $row = 1; if (($handle = fopen("https://api.thingspeak.com/channels/***/feed.csv?key=***&start=

我正在使用动态图绘制Arduino传感器数据。我需要在两个数据之间进行减法,所以我在脚本函数中使用php,但它不起作用。可以包括
    <script type="text/javascript">
        var csv = [
      '<?php
    $row = 1;
    if (($handle = fopen("https://api.thingspeak.com/channels/***/feed.csv?key=***&start=<?php echo $_POST['day_ini'];?>%20<?php echo $_POST['hour_ini'];?>&end=<?php echo $_POST['day_end'];?>%20<?php echo $_POST['hour_end'];?>", "r")) !== FALSE) {
  ...
    ?>','2015-11-02 20:54:50 UTC,1049703,5,5'
    ];

var csv=[
“2015-11-02 20:54:50 UTC,1049703,5,5”
//…等等
];
函数getPairDifference(对){
//“pair”是一个基于零的整数。
//“0”将返回csv行“0”和“1”之间的差异
//“1”将返回csv行“1”和“2”之间的差异
//等等。。。
var firstVal=parseInt(csv[pair].split(“,”[3]);
var secondVal=parseInt(csv[pair+1].split(“,”[3]);
返回firstVal-secondVal;
}
对于(变量i=0;i

提前感谢。

不需要像那样回音,您使用的是
您对PHP和Javascript的理解有误

Javascript被发送到客户端,因此它在浏览器中工作并执行get


PHP虽然首先在服务器上执行,但问题在于,您无法在客户端执行需要服务器执行的操作。

Hello.Thaks,请回答。你提到的
}
在post?中,因为在我的post中是[.我正在使用:
https://api.thingspeak.com/channels/***/feed.csv?key=***&start=2015-11-02%2020:50:45&end=2015-11-02%2020:50:45
,它工作正常。您的代码中没有结尾
}
,我只是在那里添加了。好的,我已经编辑了我的问题,以显示这个案例的动态图表功能代码。谢谢您的回复。我试图成为ca再补充一下,但我认为也许我的功能太多了?
<script type="text/javascript">
    var csv = [
  '<?php
$row = 1;
if (($handle = fopen("https://api.thingspeak.com/channels/***/feed.csv?key=***&start=2015-11-02%2020:50:45&end=2015-11-02%2021:50:45", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 50, ",")) !== FALSE) {
if($row == 1){ $row++; continue; }
    $num = count($data);
    for ($c=0; $c < $num; $c++) {
    if(strpos($data[$c], 'Finished') !== false) {
    $c++;
echo  $data[$c] . "," ; }
    Else{
        echo $data[$c] . "," ;
        }
    }
}
fclose($handle);
}
?>','2015-11-02 20:54:50 UTC,1049703,5,5'

  //... etcetera
];



        function getPairDifference(pair) {
            //"pair" is a zero-based integer.
            // "0" will return a difference between csv rows "0" & "1"
            // "1" will return a difference between csv rows "1" & "2"
            // etcetera...

            var firstVal = parseInt(csv[pair].split(",")[3]);
            var secondVal = parseInt(csv[pair + 1].split(",")[3]);
            return firstVal - secondVal;
        }

        for (var i = 0; i < csv.length; i += 1) {
            // Demo code to visualize numbers.
            // Actual function call of interest is simply "getPairDifference( i )"
            var plot = getPairDifference(i);
              //  $("<div></div>").text(plot).appendTo("body");
$(function() {
  $("#chart3").chart({
  template: "line_basic_6",
  tooltips: {
    serie1: [plot],
    width:20,
    height:15,
  },
  values: {
    serie1: [plot]
  },
  labels: ["Period 1","Period 2"],
  defaultSeries: {
    type: "bar",
    stacked: true
  },
  series: {
    serie3: {
      type: "line",
      stacked: false,
      axis: "r"
    }
  },
  axis: {
    r: {
      max: 100,
      suffix: "%"
    }
  }
});

});

$.elycharts.templates['line_basic_6'] = {
  type: "line",
  margins: [10, 40, 40, 30],
  defaultSeries: {
    highlight: {
      newProps: {
        r: 8,
        opacity: 1
      },
      overlayProps: {
        fill: "white",
        opacity: 0.2
      }
    }
  },
  series: {
    serie1: {
      color: "90-#003000-#009000",
      tooltip: {
        frameProps: {
          stroke: "green"
        }
      }
    },


  },
  defaultAxis: {
    labels: true
  },
  axis: {
    x: {
      labelsRotate: 0,
      labelsProps: {
        font: "11px Verdana"
      }
    }
  },
  features: {
    grid: {
      draw: true,
      forceBorder: true,
      ny: 5
    }
  },
  barMargins: 180

};            
        }       
    </script>
<script type="text/javascript">
        var csv = [
            '<?php
                $row = 1;
                if (($handle = fopen("https://api.thingspeak.com/channels/***/feed.csv?key=***&start={$_POST['day_ini']}%20{$_POST['hour_ini']}&end={$_POST['day_end']}%20{$_POST['hour_end']}", "r")) !== FALSE) {

                }
                ?>', '2015-11-02 20:54:50 UTC,1049703,5,5'
        ];

    </script>