Take the 2-minute tour ×

I'm new to this kind of forum and my English skills are not the best but I'll try to do my best :).

There is an example of a Line Chart with View Finder at nvd3 website. This is the one (examples\lineWithFocusChart.html, nvd3 zip package) which I have been working with during the last 2 days. I have made only one change to the example's format: I use dates in the X axis instead of normal numbers.

Here are my 2 questions:

1- How can i rotate all the ticks' labels in the x axis? My dates are too long (%x %X, day and time) and I want them rotated in oder to improve their viewing. I can only get 2 ticks rotated (the max and min, the edges, of the x axis). This is the code I modify inside the "switch (axis.orient())" block at nv.d3.js:

case 'bottom':
      axisLabel.enter().append('text').attr('class', 'axislabel')
          .attr('y', 25);
          .attr('x', scale.range()[1] / 2);
      if (showMaxMin) {
        var axisMaxMin = wrap.selectAll('g.axisMaxMin')
        axisMaxMin.enter().append('g').attr('class', 'axisMaxMin').append('text');
              return 'translate(' + scale(d) + ',0)'

            .attr('dy', '.71em')
            .attr('y', axis.tickPadding())
            .text(function(d,i) {
              return ('' + axis.tickFormat()(d)).match('NaN') ? '' : axis.tickFormat()(d)
            .attr('transform', 'rotate(45)')
              return 'translate(' + scale.range()[i] + ',0)'

As you can check i have placed .attr('transform', 'rotate(45)') as new attribute so the max and min ticks are rotated (axisMaxMin). I have tried this way (throughout the nv.d3.js file) with the other text elements that I think are associated with the x ticks but it doesnt work. Any idea? Where I have to put the transformation in order to show all the X labels rotated?

2- In the example, when you place the mouse over the line, no event is triggered to show the value (x,y) associated with the point. How can i show those values? I've tried to copy-paste the methods used in other examples where these values are showed but it doesnt work. Any idea?

Thanks for sharing your time and knowledge :D.

share|improve this question
add comment

1 Answer

up vote 13 down vote accepted

There was a recent update to nvd3 that makes rotating the x-axis tick labels really easy. There is now a function of the axis model called rotateLabels(degrees) that takes an integer and will rotate your xTick labels the specified number of degrees. To rotate all xTick labels 45 degrees back, you could use it like this:

var chart = nv.models.lineChart();
share|improve this answer
Note: this doesn't seem to work if you're also using: .staggerLabels(true) –  DuffJ Oct 21 '13 at 21:28
add comment

Your Answer


