从json绘制高脚椅中的股价图表



在高位图中绘制以下来源的股票数据的最佳方法是什么?我一直在摆弄,但我无法获得正确格式的数据。

https://financialmodelingprep.com/api/v3/historical-price-full/AAPL?apikey=1920dcbb65f52e51cf4ceb45d64d6bd9

谢谢,Bruce

您需要解析数据,以便Highcharts能够读取数据。

示例代码:

var ohlc = [],
volume = [],
vwap = [],
mainData = data.historical.length,
i = 0;
for (i; i < mainData; i += 1) {
let date = data.historical[i].date,
utcTimestamp = new Date(date).getTime();
ohlc.push([
utcTimestamp, // the date
data.historical[i].open, // open
data.historical[i].high, // high
data.historical[i].low, // low
data.historical[i].close // close
]);
volume.push([
utcTimestamp, // the date
data.historical[i].volume // the volume
]);
vwap.push([
utcTimestamp, // the date
data.historical[i].vwap // the volume
]);
}

数据https://jsfiddle.net/BlackLabel/cjt918Lv/

注意:

  • 的指标必须包括相关模块
  • 日期必须以时间戳格式提供
  • Highcharts中的数据应该按升序排序,因此您需要反转它们

API参考:https://api.highcharts.com/highstock/series.ohlchttps://api.highcharts.com/highstock/series.volumehttps://api.highcharts.com/highstock/series.vwap

最新更新