在php代码var anidade中发布请求

时间:2015-11-24 09:28:19

标签: javascript php charts

我正在使用Dygraphs绘制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'
    ];

这是我的所有功能代码:

<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>

提前致谢。

2 个答案:

答案 0 :(得分:0)

不需要像那样回应,并且在关闭它之前在另一个 package com.example.tatson.bila; /** * Created by Tatson on 23-11-2015. */ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener { public static String TAG = EndlessRecyclerOnScrollListener.class.getSimpleName(); private int previousTotal = 0; // The total number of items in the dataset after the last load private boolean loading = true; // True if we are still waiting for the last set of data to load. private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more. int firstVisibleItem, visibleItemCount, totalItemCount; private int current_page = 1; private LinearLayoutManager mLinearLayoutManager; public EndlessRecyclerOnScrollListener(LinearLayoutManager linearLayoutManager) { this.mLinearLayoutManager = linearLayoutManager; } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); visibleItemCount = recyclerView.getChildCount(); totalItemCount = mLinearLayoutManager.getItemCount(); firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition(); if (loading) { if (totalItemCount > previousTotal) { loading = false; previousTotal = totalItemCount; } } if (!loading ) { // End has been reached // Do something current_page++; Log.d("End", "Sucess"); onLoadMore(current_page); loading = true; } } public abstract void onLoadMore(int current_page); } 内使用<?php

<?php

我不确定<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> ,请检查一次。

答案 1 :(得分:0)

您误解了PHP和Javascript的内容。

Javascript被发送到客户端,因此它可以在浏览器中运行并且也可以执行。

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