我正在寻找帮助将数据从dbase加载到Higtcharts。 Highcharts数据加载入口看起来像:
<script type="text/javascript">
jQuery(function() {
// Create the chart
window.chart = new Highcharts.StockChart({
chart: {
renderTo: 'container'
},
rangeSelector: {
selected: 1
},
title: {
text: 'USD to EUR exchange rate'
},
xAxis: {
maxZoom: 14 * 24 * 3600000 // fourteen days
},
yAxis: {
title: {
text: 'Exchange rate'
}
},
series: [{
name: 'USD to EUR',
data: usdeur
}]
});
});
</script>
和usdeur正在加载方案(例如来自外部csv文件):
var usdeur = [
[Date.UTC(2011,1,3),0.7488],
[Date.UTC(2011,2,6),0.6983],
[Date.UTC(2011,3,8),0.6961],
[Date.UTC(2011,4,9),0.6945]
];
来自dbase SELECT我有:
$data_date = array();
$data_data = array();
foreach($STH as $row)
{
$date1 = $row['date'];
$date2 = explode("-", $date1);
$date3 = $date2[0].",".$date2[1].",".$date2[2];
$data_date[] = $date3; // date in scheme 2011,1,3
$data_data[] = $row['index_p_actual']; // data like 0.7488
}
我想在线加载数据,而不是通过任何外部文件,如csv。
我的问题是 - 如何将$ data_date和$ data_data连接到一个数据包中以接收完整的虚拟列表,如
[Date.UTC(2011,1,3),0.7488],
[Date.UTC(2011,2,6),0.6983],
[Date.UTC(2011,3,8),0.6961],
[Date.UTC(2011,4,9),0.6945]
来自highcharts的建议是使用:
series: [{
data: [<?php echo join($data, ',') ?>]
}]
但我有$ data&amp; $ date - 如何加入?使用php join我只能使用一个变量[] ...
嗯,或者可能是另一种更好的方式?答案 0 :(得分:0)
如果我理解你,我想你想这样做:
$data_date = array();
$data_data = array();
foreach($STH as $row)
{
$date1 = $row['date'];
$date2 = explode("-", $date1);
$date3 = $date2[0].",".$date2[1].",".$date2[2];
$data_date[] = $date3; // date in scheme 2011,1,3
$data_data[] = $row['index_p_actual']; // data like 0.7488
$data_highcharts[] = [$date3,$row['index_p_actual']]
}
然后您将$data_highcharts[]
发送到您的JavaScript,其格式为:
[[date1,data1],[date2,data2],...]