With NVD3.js (nv.models.lineWithFocusChart), how do you set specific ticks on X-axis, when x values are dates?

Posted by Panagiotis Panagi on Stack Overflow See other posts from Stack Overflow or by Panagiotis Panagi
Published on 2013-07-03T10:55:11Z Indexed on 2013/07/03 11:05 UTC
Read the original article Hit count: 1346

Filed under:
|
|

I'm using nv.models.lineWithFocusChart, where I'm showing some hourly measurements. So the x domain is dates.

What I need is to show a tick per hour on X axis:

00:00 01:00 02:00 ... 24:00

I've tried everything I could find but nothing works. It seems that its easy to set specific ticks when values are not dates. But can't figure out how to do it for dates.

Here's the code that creates the graph, if it can help:

 nv.addGraph ->
    chart = nv.models.lineWithFocusChart(view)
    chart.yAxis.tickFormat(d3.format(".02f"))

    d3.select(graphSelector).datum([]).transition().duration(500).call(chart)
    nv.utils.windowResize ->
      d3.select(graphSelector).call(chart)

    chart.xAxis.tickFormat (d) ->
      d3.time.format(ticksFormat)(new Date(d)) 
    chart.x2Axis.tickFormat (d) ->
      d3.time.format(ticksFormat)(new Date(d))

    chart.xAxis.tickSubdivide(9)

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about d3.js