Highcharts有關於如何將JSON文件合併到圖表中的一些很好的例子,但他們的例子是pretty simple JSON files。如何使用JSON將勞動統計數據庫導入Highcharts?
這是我想要做的。
取本實施例從的jsfiddle(http://jsfiddle.net/xhz7oujw/):
HTML:
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
JAVASCRIPT:
$(function() {
$('#container').highcharts({
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}]
});
,並與來自BLS此文件(http://api.bls.gov/publicAPI/v2/timeseries/data/LASST410000000000003)替換數據:
{
"status": "REQUEST_SUCCEEDED",
"responseTime": 16,
"message": [
],
"Results": [
{
"series": [
{
"seriesID": "LAUCN040010000000005",
"data": [
{
"year": "2013",
"period": "M11",
"periodName": "November",
"value": "16393",
"footnotes": [
{
"code": "P",
"text": "Preliminary."
}
]
},
{
"year": "2013",
"period": "M10",
"periodName": "October",
"value": "16536",
"footnotes": [
{
...
}
]
}
]
}
]
}
我只是想用「年」和「期」替換y軸數據,並用「值」替換這些值。我的問題是我不知道如何以一種很好的格式獲取這些文件,例如something like this。