PHP array to Highcharts
PHP array to Highcharts
如何从数组到Highcharts获取此数据?
[0] => Array
(
[0] => Date
[1] => data1
[2] => data2
)
[1] => Array
(
[0] => 2015-03-26 02:00
[1] => 1,425
[2] => 39,294
)
[2] => Array
(
[0] => 2015-03-26 03:00
[1] => 1,422
[2] => 39,076
)
我是PHP的新手,正在寻找一种方法来获得第一个键(日期)作为x轴,key2 (data2)作为y轴。可以通过选择数组中的所有键值,并将其传递给这个javascript的Highcharts吗?
$(function () {
$('#container').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Chart Title'
},
xAxis: {
categories: //Dates here 2015-03-26 02:00//
},
yAxis: {
title: {
text: 'a text here'
}
},
series: [{
name: 'data1',
data: // key1 from array 1,425 //
}, {
name: 'data2',
data: // key2 from array 39,294 //
}]
});
});
$data = array
(
array
(
"Date",
"data1",
"data2"
),
array
(
"2015-03-26 02:00",
"1,425",
"39,294"
),
array
(
"2015-03-26 03:00",
"1,422",
"39,076"
)
);
$series = array();
// Get the items of the first array
$items = $data[0];
foreach($items as $itemIndex => $value)
{
// Skip the 'Date'
if (!$itemIndex)
continue;
// We should have the actual array to add to the 'data', if not skip
if (empty($data[$itemIndex]))
continue;
$series[] = array
(
"name" => $value,
"data" => $data[$itemIndex]
);
}
echo json_encode($series);
相关文章:
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- 在Web应用程序中使用Highcharts javascript
- 在Highcharts中,我们可以通过任何方式在渲染图表之前获得plotWidth和plotHeight
- HighCharts长标题文本在某些元素上重叠
- jQuery AJAX write to XML
- Highcharts colorsByPoint与系列中的线性渐变一起使用时不起作用
- grep in JQuery to C#
- how to convert html <div> to pdf
- Highcharts-如何在自定义格式化程序中获得默认的y轴标签格式化程序
- Highcharts仪表未显示
- Node.js - POST to iFrame?
- Highcharts-图表外的图例定位
- SVG xml to image
- Advantages to DOMParser vs template & innerHTML
- how to split a string with ','
- Highcharts动态烛台
- How to declare a Map containing certain properties with flow
- Highcharts - export to base64
- javascript Highcharts JSON data to HTML table
- PHP array to Highcharts