Mike Rifgin
Mike Rifgin

Reputation: 10761

Why isn't month shown on my X Axis?

Can anyone explain why Janaury is not bening shown on my x Axis?

http://jsfiddle.net/bwNj6/

I'm using this to generate it:

var xAxis = d3.svg.axis()
.scale(x)
.ticks(d3.time.months)
.orient("bottom").tickFormat(d3.time.format("%B"));

Upvotes: 0

Views: 90

Answers (1)

nsonnad
nsonnad

Reputation: 634

It's because you don't have any data on or before January 1st, and are calling the domain of the x axis with d3.extent(), so the axis stops at your lowest value (January 3rd or something around there). Instead of using d3.extent(), you can manually choose to decide to start your axis on January 1st like so:

x.domain([
  new Date('2012/1/1'),
  d3.max(data, function(d) { return d.date; })
]);

Updated fiddle here

Upvotes: 1

Related Questions