Saurabh Sinha
Saurabh Sinha

Reputation: 1800

printing date in different format on x-axis in d3.js

I am using D3.js to build this line chart.and its working fine . but i am not able to print the months on x-axis in abbreviated form (jan,feb....)

here how i am parsing the date.

var parseDate = d3.time.format("%m-%Y").parse;

the code for x-axis

var xAxis = d3.svg.axis().scale(x).orient("bottom");

and printing and appending

svg.append("g")
  .attr("class", "x axis")
  .attr("transform", "translate(0," + height + ")")
  .call(xAxis);

help me with this.

Upvotes: 2

Views: 2863

Answers (1)

DMTintner
DMTintner

Reputation: 14729

just use tickFormat with a d3.time.format inside

var xAxis = d3.svg.axis().scale(x).orient("bottom").tickFormat(d3.time.format("%H"))

Upvotes: 5

Related Questions