javascript - How to convert time range to display in hours not date? (nvd3 chart) -


http://plnkr.co/edit/19d5cnrvydurmlblqary?p=preview

enter image description here

above chart, values i've passed 1 day, 30 minute intervals:

var data =[{   "key" : "price",   "color" : "#4c73ff",   "values" : [ [ 1443621600000 , 71.89],                [ 1443619800000 , 75.51],                [ 1443618000000 , 68.49],                [ 1443616200000 , 62.72],                [ 1443612600000 , 70.39],                [ 1443610800000 , 59.77]] }]; 

which correspond following (epoch converter):

9/30/2015, 9:00:00 gmt-5:00 dst 9/30/2015, 8:30:00 gmt-5:00 dst 9/30/2015, 8:00:00 gmt-5:00 dst 9/30/2015, 7:30:00 gmt-5:00 dst 9/30/2015, 6:30:00 gmt-5:00 dst 9/30/2015, 6:00:00 gmt-5:00 dst 

how change format of date on chart showing 9/30/2015 show instead 9:00?

i couldn't find in docs talking time or timespans http://nvd3-community.github.io/nvd3/examples/documentation.html#line

full code directive:

var data =[{   "key" : "price",   "color" : "#4c73ff",   "values" : [ [ 1443621600000 , 71.89],                [ 1443619800000 , 75.51],                [ 1443618000000 , 68.49],                [ 1443616200000 , 62.72],                [ 1443612600000 , 70.39],                [ 1443610800000 , 59.77]] }];  nv.addgraph(function() {   var chart = nv.models.lineplusbarchart()     .margin({top: 30, right: 60, bottom: 50, left: 70})     .x(function(d,i) { return })     .y(function(d) { return d[1] })     .color(d3.scale.category10().range());    chart.xaxis     .showmaxmin(false)     .tickformat(function(d) {       var dx = data[0].values[d] && data[0].values[d][0] || 0;       return d3.time.format('%x')(new date(dx))     });    chart.y1axis     .tickformat(d3.format(',f'));    chart.y2axis     .tickformat(function(d) { return '$' + d3.format(',f')(d) });    chart.bars.forcey([0]);    d3.select('#chart svg')     .datum(data)     .transition().duration(500)     .call(chart);    nv.utils.windowresize(chart.update);    return chart; }); 

just found question understanding nvd3 x-axis date format

which helped me find this: https://github.com/mbostock/d3/wiki/time-formatting

i'm able correct change time now:

from timerangeconvertfactory service made

function converttime(when) {     switch(when) {         case 'lh':         case 'ld':             return '%i:%m';             break;         case 'lw':         case '1mo':         case '3mo':             return '%x';             break;         case '1yr':         case '2yr':         case 'max':             return '%m:%y';             break;     } } 

and in directive:

// timespan: var timerange = timespanfactory.gettimespan(); console.log('timerange =',timerange.when);  // convert timespan nvd3 format: var nvd3timerange = timespanconvertfactory.converttime(timerange.when); console.log('nvd3timerange =',nvd3timerange);  nv.addgraph(function() {     var chart = nv.models.lineplusbarchart()         .margin({top: 20, right: 40, bottom: 50, left: 40})         .x(function(d,i) { return })         .y(function(d) { return d[1] })         .color(d3.scale.category10().range());      chart.xaxis.tickformat(function(d) {         var dx = res[0].values[d] && res[0].values[d][0] || 0;         return d3.time.format(nvd3timerange)(new date(dx))         // return d3.time.format('%i:%m')(new date(dx))         // return d3.time.format('%x')(new date(dx))     });     .... 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -