jquery - nvd3 linebar chart xAxis date format -
i have working line , bar chart having problems getting date format appropriately on xaxis. did around couldn't find linebar chart examples out there used same date format need.
here json stored variable looks like:
var data = [{ "key": "cases", "bar": true, "color": "skyblue", "values": [ [2016-01-01, 13], [2016-01-02, 17], [2016-01-03, 19], [2016-01-04, 39], [2016-01-05, 46], [2016-01-06, 34], [2016-01-07, 36], [2016-01-08, 32] ] }, { "key": "csat", "color": "steelblue", "values": [ [2016-01-01, 9], [2016-01-02, 7], [2016-01-03, 10], [2016-01-04, 10], [2016-01-05, 8], [2016-01-06, 9], [2016-01-07, 10], [2016-01-08, 10] ] } ];
i believe part of code needs review:
chart.xaxis.showmaxmin(true) .tickformat(function (d) { var dx = data[0].values[d] && data[0].values[d][0] || 0; return d3.time.format('%y-%d-%m')(new date(dx)); });
this code written date in epoch/unix format, however, json has different format date - looks 2016-01-01 %y-%d-%m
.
you can view whole chart code here: http://jsfiddle.net/pty79q2z/
thanks in advance!
Comments
Post a Comment