Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

abbreviated month format for x-axis in d3.js

how to convert the full month name to abbreviated name by this function

axis.ticks(d3.time.months, 1)

this function prints the months name in full january February

What should i use to change it to abbreviated names.

like image 241
Saurabh Sinha Avatar asked Jan 25 '13 13:01

Saurabh Sinha


2 Answers

You can add a timeFormat, like this:

axis.ticks(d3.time.months, 1)
   .tickFormat(d3.time.format("%b"));
like image 53
mortsen Avatar answered Sep 30 '22 08:09

mortsen


The accepted answer was answered before d3 version 4 release. If you want to do the same with d3 version 4, do it like this:

axis.ticks(d3.timeMonth, 1)
  .tickFormat(d3.timeFormat('%b'));
like image 45
Mikhail Shabrikov Avatar answered Sep 30 '22 08:09

Mikhail Shabrikov