score:1

Accepted answer

So, pretty big hack here but you could parse out the location of the axis and add it yourself:

var startTick = 1,
      endTick = 3;
  var x1 = parseFloat(d3.select(d3.selectAll('.nv-x .tick')[0][startTick]).attr('transform').split("(")[1]);
  var x2 = parseFloat(d3.select(d3.selectAll('.nv-x .tick')[0][endTick]).attr('transform').split("(")[1]);
  d3.select('.nv-y .tick')
    .append('line')
    .attr('x1', x1)
    .attr('x2', x2)
    .style('stroke', 'black')
    .style('stroke-width', 10);

EDITS

I just re-thought this. Instead of parsing location out of the DOM you can get it back from the chart object. Much cleaner this way:

var x1 = chart.xScale()(1122782400000);
var x2 = chart.xScale()(1251691200000);
var height = chart.yAxis.range()[0];

// line on x-axis
d3.select('.nv-y .tick')
  .append('line')
  .attr('x1', x1)
  .attr('x2', x2)
  .style('stroke', 'black')
  .style('stroke-width', 10);

// shaded background
d3.select('.nv-y')
  .append('rect')
  .attr('x', x1)
  .attr('width', x2 - x1)
  .style('fill', 'steelblue')
  .style('opacity', 0.2)
  .attr('y', 0)
  .attr('height', height);

Example here.


Related Query