【发布时间】:2017-12-11 19:39:54
【问题描述】:
我正在尝试从此 JSON 中获取数据:https://min-api.cryptocompare.com/data/histominute?fsym=BTC&tsym=USD&limit=60&aggregate=3&e=CCCAGG
进入hightcharts。
我有这张图表可以正常工作,但我无法为上面的 JSON 获得正确的格式:仍在学习 javascript。而且我喜欢逐个项目地学习,至少有一些原因:)
另外,这个时间戳让我很烦......
$.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?', function (data) {
var ohlc = [],
volume = [],
dataLength = data.length,
groupingUnits = [[
'week',
[1]
], [
'month',
[1, 2, 3, 4, 6]
]],
i = 0;
for (i; i < dataLength; i += 1) {
ohlc.push([
data[i][0], // the date
data[i][1], // open
data[i][2], // high
data[i][3], // low
data[i][4] // close
]);
volume.push([
data[i][0], // the date
data[i][5] // the volume
]);
}
// create the chart
Highcharts.stockChart('container', {
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Historical'
},
yAxis: [{
labels: {
align: 'right',
x: -3
},
title: {
text: 'OHLC'
},
height: '60%',
lineWidth: 2,
resize: {
enabled: true
}
}, {
labels: {
align: 'right',
x: -3
},
title: {
text: 'Volume'
},
top: '65%',
height: '35%',
offset: 0,
lineWidth: 2
}],
tooltip: {
split: true
},
series: [{
type: 'candlestick',
name: 'AAPL',
data: ohlc,
dataGrouping: {
units: groupingUnits
}
}, {
type: 'column',
name: 'Volume',
data: volume,
yAxis: 1,
dataGrouping: {
units: groupingUnits
}
}]
});
});
有人可以帮忙吗?如何从该 JSON 中正确分离信息并对其进行格式化,以便 highcharts 可以将其可视化?
提前感谢您的帮助!
【问题讨论】:
标签: javascript json api highcharts