我使用了图表,我想显示数据库中的数据。问题是图表未显示。这是我第一次使用JSON。我的查询中出了什么问题,这就是为什么该图未显示的原因?
脚本
$(function() {
$.getJSON('fetchdata.php',function($wv3) {
Highcharts.chart('container', {
chart: {
type: 'line'
},
title: {
text: 'Daily Voltage'
},
xAxis: {
categories: ['12:00 AM', '1:00 AM', '2:00 AM', '3:00 AM', '4:00 AM', '5:00 AM', '6:00 AM', '7:00 AM', '8:00 AM', '9:00 AM', '10:00 AM', '11:00 AM','12:00 PM', '1:00 PM', '2:00 PM', '3:00 PM', '4:00 PM', '5:00 PM', '6:00 PM', '7:00 PM', '8:00 PM', '9:00 PM', '10:00 PM', '11:00 PM']
},
yAxis: {
title: {
text: 'Voltage A'
}
},
plotOptions: {
line: {
dataLabels: {
enabled: true
},
enableMouseTracking: false
}
},
series: [{
name: 'Feeder 1',
data: wv3
}]
});
});
});
HTML
</div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
fetchdata.php
$weekly1 = "SELECT DISTINCT FORMAT(CAST(Batal_Feeder_1.time as datetime) , 'MM/dd/yyyy HH') as Time,
Batal_Feeder_1.Ia, Batal_Feeder_1.Ib, Batal_Feeder_1.Ic, Batal_Feeder_1.Kwtotal, Batal_Feeder_1.pftotal,Batal_Feeder_1.Kwhtotal, Va AS VoltageA
FROM Batal_Feeder_1
JOIN (
SELECT MIN(time) as mints FROM Batal_Feeder_1
WHERE CONVERT(DATETIME, FLOOR(CONVERT(FLOAT, time))) = '".$_SESSION['date']."'
GROUP BY CONVERT(date,time), DATEPART(hh, time)
)tt
ON Batal_Feeder_1.time = tt.mints
ORDER BY Time ASC";
$weekly2 = sqlsrv_query($db, $weekly1);
while($row = sqlsrv_fetch_array($weekly2)) {
$wv1 = $row['VoltageA'];
$wv2 = $row['time'];
$wv3[] = [$wv1];
}
echo json_encode($wv3);