Short month format for x axis in d3.js

How to convert the full month name to an abbreviated name using this function

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

this function prints the name of the month in full January February

What should I use to change it to abbreviated names.

+6
source share
2 answers

You can add timeFormat , for example:

 axis.ticks(d3.time.months, 1) .tickFormat(d3.time.format("%b")); 
+14
source

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

 axis.ticks(d3.timeMonth, 1) .tickFormat(d3.timeFormat('%b')); 
0
source

All Articles