使用按钮“ $ Post”方法过滤数据。 必须选择两个日期,它将用于过滤JSON数据。
我有两个密码。
streamchart.php -显示json数据的地方。
stream.php -在图表中显示数据。
我的问题是如何根据日期范围过滤json数据?
Stream.php
<?php
include ('connection/conn.php');
$sth = mysqli_query($conn, "SELECT val FROM tbl_streamflow WHERE araw = '2018-11-18'");
$rows = array();
$rows['name'] = 'Previous';
while($r = mysqli_fetch_array($sth)) {
$rows['data'][] = $r['val'];
}
$sth1 = mysqli_query($conn, "SELECT val FROM tbl_streamflow WHERE araw = '2018-11-26'");
$rows1 = array();
$rows1['name'] = 'Current';
while($rr = mysqli_fetch_assoc($sth1)) {
$rows1['data'][] = $rr['val'];
}
$result = array();
array_push($result,$rows);
array_push($result,$rows1);
//print json_encode($result, JSON_NUMERIC_CHECK);
echo json_encode($result, JSON_NUMERIC_CHECK);
?>
StreamChart.php
<script type="text/javascript">
$(function () {
var chart;
$(document).ready(function() {
$.getJSON("streamchart.php", function(json) {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'spline',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'StreamFlow Discharge Previous (Nov.18.2018) vs. Current (Nov.26.2018)',
style: { "color": "#333333", "fontSize": "25px" },
x: -20 //center
},
subtitle: {
text: 'StreamFlow Discharge Result',
x: -20
},
xAxis: {
categories: ['SW-009', 'SW-028', 'SW-029', 'SW-010', 'SW-001', 'SW-007', 'SW-012']
},
yAxis: {
title: {
style: { "color": "#333333", "fontSize": "15px" },
text: 'Discharge m3/s'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
crosshairs: true,
shared: true
},
plotOptions: {
spline: {
marker: {
radius: 4,
lineColor: '#666666',
lineWidth: 1
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: json
});
});
});
});
</script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
请帮助我。谢谢!