0
votes

AlphaVantage Time series looks like this: { "Meta Data": { "1. Information": "Daily Prices (open, high, low, close) and Volumes", "2. Symbol": "IBM", "3. Last Refreshed": "2020-11-19", "4. Output Size": "Compact", "5. Time Zone": "US/Eastern" }, "Time Series (Daily)": { "2020-11-19": { "1. open": "116.5400", "2. high": "117.4500", "3. low": "115.8900", "4. close": "117.1800", "5. volume": "3331942" }, "2020-11-18": { "1. open": "117.7200", "2. high": "118.8800", "3. low": "116.7500", "4. close": "116.7700", "5. volume": "4606828" }, "2020-11-17": { "1. open": "117.6000", "2. high": "118.5400", "3. low": "117.0700", "4. close": "117.7000", "5. volume": "4134455" }.....

So what I would like is just the date in INTEGER format to use as index and just the column "4. close" something like this (n.b. these are totally random number just as output example):

[ [ 1519344000000, 9850.78, ], [ 1519430400000, 10171.3, ], [ 1519516800000, 9699.76, ], ......

Can anyone help with that? thanks

1

1 Answers

0
votes

You need to parse the data to the format required by Highcharts, for example:

var processedData = [];

for (var key in data['Time Series (Daily)']) {
    processedData.push({
        x: new Date(key).getTime(),
        open: parseFloat(data['Time Series (Daily)'][key]['1. open']),
        high: parseFloat(data['Time Series (Daily)'][key]['2. high']),
        low: parseFloat(data['Time Series (Daily)'][key]['3. low']),
        close: parseFloat(data['Time Series (Daily)'][key]['4. close'])
    });
}

Highcharts.stockChart('container', {
    ...,
    series: [{
        type: 'ohlc',
        data: processedData.reverse()
    }]
});

Live demo: http://jsfiddle.net/BlackLabel/n4ev91g3/

API Reference: https://api.highcharts.com/highstock/series.ohlc