d3.js - nvd3 - Format Milliseconds to h:m:s in Chart (Period of Time, not Date) -
i've managed display dates in d3/ nvd3 charts, did passing value of milliseconds:
chart.xaxis .tickformat(function(d) { return d3.time.format('%e, %h:%m')(new date(d)) });
i'd display milliseconds period of time on y-axis, "6 h : 23 min : 5 sec".
is possible?
thanks in advance!
muff
try
d3.time.format('%h h : %m min : %s sec')(new date())
it format date this
05 h : 34 min : 26 sec
or if don't 0 padding hours do
d3.time.format('%-h h : %m min : %s sec')(new date())
it format date this
5 h : 37 min : 54 sec
edit
in such case need put if block check , return desired format this:
.tickformat(function(d) { var date = new date(d); if (date.gethours() == 0){ return d3.time.format('%m min : %s sec')(d) } else { return d3.time.format('%-h h : %m min : %s sec')(d) } }
Comments
Post a Comment