Javascript 实时数据图表不工作
大家好,我正在制作实时java脚本图表,以显示数据库中的数据,但我得到的是什么都没有,它没有从数据库中捕获数据 我使用了这个php代码Javascript 实时数据图表不工作,javascript,php,html,highcharts,Javascript,Php,Html,Highcharts,大家好,我正在制作实时java脚本图表,以显示数据库中的数据,但我得到的是什么都没有,它没有从数据库中捕获数据 我使用了这个php代码 <?php header("Content-type: text/json"); $servername = "localhost"; $username = "root"; $password = ""; $value = $_GET['value']; $date = time() * 1000;
<?php
header("Content-type: text/json");
$servername = "localhost";
$username = "root";
$password = "";
$value = $_GET['value'];
$date = time() * 1000;
$ret = array($date, $value);
echo json_encode($ret);
$conn = mysql_connect($servername, $username, $password);
if ($conn) {
echo "Connected successfully";
}
else {
echo "connection failed";
}
$conndb = mysql_select_db('database', $conn);
echo "<br>";
$sql_insert ="insert into pulsesensor(value) values ('$value')";
if($sql_insert){
echo "insert successfull";
}
else {
echo "insert failed";
} echo "<br>";
$result = mysql_query($sql_insert);
if($result){
echo "insert successfull";
}
else {
echo "insert failed" . mysql_error($result);
}
?>
你的mysql0.php
是什么?如果打开“开发人员工具”并查看“网络”选项卡,脚本是否发送请求?它有什么回报吗?它返回的数据是什么样子的?您的控制台中有错误吗?@Dimi my mysql0.php是我向服务器发送数据的php代码,数据正确发送并插入到数据库中,但我不知道是否正确返回,我有一个网站将数据库值显示为表,这也是idk为什么java脚本看不到服务器输出的数据值。
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0
auto">
</div>
/**
* Request data from the server, add it to the graph and set a timeout
* to request again
*/
function requestData() {
$.ajax({
url: 'mysql0.php',
success: function(point) {
var series = chart.series[0],
shift = series.data.length > 20; // shift if the series is
// longer than 20
// add the point
chart.series[0].addPoint(point, true, shift);
// call it again after one second
setTimeout(requestData, 1000);
},
cache: false
});
}
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'spline',
events: {
load: requestData
}
},
title: {
text: 'Live Heartbeats data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150,
maxZoom: 20 * 1000
},
yAxis: {
minPadding: 0.2,
maxPadding: 0.2,
title: {
text: 'Value',
margin: 80
}
},
series: [{
name: 'heartbeats data',
data: []
}]
});
});
</script>