0
我想在highchart中顯示mysql數據庫。我找到了一個從文檔中獲取數據的例子,但我想使用函數。當我使用功能程序不起作用。函數的輸出與更改前的文檔相同。也許在函數或者我使用它的方式上有一些錯誤。PHP + mysql + highcharts
這是我的代碼:
<? $data = new MysqlDatabase($db) ?>
<script type="text/javascript">
var chart;
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
defaultSeriesType: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Date',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
type: 'datetime',
tickInterval: 3600 * 1000, // one hour
tickWidth: 0,
gridLineWidth: 1,
labels: {
align: 'center',
x: -3,
y: 20,
formatter: function() {
return Highcharts.dateFormat('%l%p', this.value);
}
}
},
yAxis: {
title: {
text: 'Humidity'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return Highcharts.dateFormat('%l%p', this.x-(1000*3600)) +'-'+ Highcharts.dateFormat('%l%p', this.x) +': <b>'+ this.y + '</b>';
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: [{
name: 'Count'
}]
}
jQuery.get(<?php $data->find_all_for_charts($db);?>, null, function(tsv) {
var lines = [];
traffic = [];
try {
// split the data return into lines and parse them
tsv = tsv.split(/\n/g);
jQuery.each(tsv, function(i, line) {
line = line.split(/\t/);
date = Date.parse(line[0] +' UTC');
traffic.push([
date,
parseInt(line[1].replace(',', ''), 10)
]);
});
} catch (e) { }
options.series[0].data = traffic;
chart = new Highcharts.Chart(options);
});
});
</script>
功能代碼:
<?php
class MysqlDatabase
{
public function find_all_for_charts($db)
{
$stmt = $db->query('SELECT * FROM temperature');
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo $row['timestamp'] . "\t" . $row['humidity'] . "\n";
}
}
}
?>
不是函數此示例中使用的文件的名稱:我怎樣才能解決
jQuery.get(<?php $data->find_all_for_charts($db);?>, null, function(tsv) {
你的問題?提前致謝。 :)