I am using nvd3, but I think this is a general d3.js question about time scale and formatting. I created a simple example that illustrates the problem (see code below):
If I omit .tickFormat for xAxis, it works fine without date formatting. In the example below, I get an error:
Uncaught TypeError: Object 1326000000000 does not have a getMonth method
nv.addGraph(function() { var chart = nv.models.lineChart(); chart.xAxis .axisLabel('Date') .rotateLabels(-45) .tickFormat(d3.time.format('%b %d')) ; chart.yAxis .axisLabel('Activity') .tickFormat(d3.format('d')); d3.select('#chart svg') .datum(fakeActivityByDate()) .transition().duration(500) .call(chart); nv.utils.windowResize(function() { d3.select('#chart svg').call(chart) }); return chart; }); function days(num) { return num*60*60*1000*24 } function fakeActivityByDate() { var lineData = []; var y = 0; var start_date = new Date() - days(365);
An example (now fixed) is in nvd3 with a date axis .
Ultrasaurus Dec 27 2018-12-12T00: 00Z
source share