tickformat for d3.js time scale

前端 未结 1 1696
栀梦
栀梦 2021-01-25 19:45

I am using a d3.js time.scale like this:

var xScale = d3.time.scale()
        .domain(d3.extent(data, function(d) { return d.date; }))
        .rang         


        
相关标签:
1条回答
  • 2021-01-25 20:24

    If you want the ticks to show the month name and the year, add this to the axis:

    .tickFormat(d3.time.format("%B %Y"));
    

    Alternatively, you can display the abbreviated month name:

    .tickFormat(d3.time.format("%b %Y"));
    

    Here is the updated jsbin: http://jsbin.com/wikafuluqu/1/edit?js,output

    PS: To show the first tick, add nice() to the scale. This is the jsbin with nice(): http://jsbin.com/loyupelazu/1/edit?js,output

    0 讨论(0)
提交回复
热议问题