d3.js - Converting seconds to minutes and formatting axes -
i have data in format of seconds. convert seconds data hours , minutes , display data along axis. example, i've been trying this:
var xaxis = d3.svg.axis() .scale(x) .orient("bottom") .tickformat(function(d) {return d/60});
i see d3 has time formatter, can't seem display proper format. i'm looking a way in d3 convert data in seconds hours , minutes. how can this?
var xaxis = d3.svg.axis() .scale(x) .orient("bottom") .tickformat(function(d) { var minutes = math.floor(d / 60000); var seconds = +((d % 60000) / 1000).tofixed(0); return (seconds == 60 ? (minutes+1) + ":00" : minutes + ":" + (seconds < 10 ? "0" : "") + seconds); });
this convert milliseconds minutes , seconds.
Comments
Post a Comment