javascript - Formatting dates in HighCharts -
i have following code:
<script> $.getjson('https://www.quandl.com/api/v3/datasets/opec/orb.json?order=asc', function(json) { var hijson = json.dataset.data.map(function(d) { return [new date(d[0]), d[1]] }); // create chart $('#container').highcharts('chart', { rangeselector: { selected: 1 }, title: { text: 'opec crude oil price', }, series: [{ type: 'line', name: 'opec', data: hijson, }] }); }); which prints beautiful chart follows:
but can see, dates not in correct format. struggling work out wrong?
all appreciated always!
update:
so holvar's comment solved 1 problem, have on same theme.
my code follows:
<script> $.getjson('https://www.quandl.com/api/v3/datasets/boe/iuaaamih.json?auth_token=pg6fbmvfqazvfdugpqhz&start_date=2003-01-02&order=asc', function(json) { var hijson = json.dataset.data.map(function(d) { return [new date(d[0]), d[1]] }); // create chart $('#interest').highcharts('chart', { xaxis: { type: 'datetime', datetimelabelformats: { day: '%y' } }, rangeselector: { selected: 1 }, title: { text: 'uk interest rates', }, series: [{ type: 'line', name: 'interest rate', data: hijson, }] }); }); but produces chart without dates on bottom. i'd years 2003-01-02. chart looks this
i don't understand why it's not showing annual date in solution posed question?!
you appreciated!
i believe issue way data map happening. ending array contains multiple arrays, instead of object "x" , "y" properties. try changing initialization of hijson variable like:
var hijson = json.dataset.data.map(function(d) { return { x: new date(d[0]), y: d[1] }; });
that seems working on local environment.
Comments
Post a Comment