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

2020-04-14 12:31发布

问题:

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.

回答1:

just use tickFormat with a d3.time.format inside

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