title: D3 grid lines and tick values issues
body: <p>I have a stacked area chart made using D3. I am facing two issues with my implementation.</p>
  
  <p>1) i just want to display alternative tick values on the y axis. For example in my implementation y axis values are <code>0, 20, 40, 60, 80, 100</code> and so on. But i want to show values likes <code>0, 40, 80, 120</code> but also keeping corresponding grid line. i just want to remove alternative tick value without removing the y-axis grid line.</p>
  
  <p>2) i want to format the y-axis, so that it should always have upper y-axis grid line. So in my implementation i wish to have a grid line above <code>180</code> value.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var margin = {
      top: 20,
      right: 30,
      bottom: 30,
      left: 40
    },
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;
  
  var x = d3.time.scale()
    .range([0, width]);
  
  var y = d3.scale.linear()
    .range([height, 0]);
  
  var z = d3.scale.category20c();
  
  var xAxis = d3.svg.axis()
    .scale(x)
    .orient("bottom")
  
  
  var yAxis = d3.svg.axis()
    .scale(y).innerTickSize(-width).outerTickSize(0)
    .orient("left");
  
  var stack = d3.layout.stack()
    .offset("zero")
    .values(function(d) {
      return d.data;
    })
    .x(function(d) {
      return new Date(d[0]);
    })
    .y(function(d) {
      return d[1];
    });
  
  
  
  var area = d3.svg.area()
    .interpolate("cardinal")
    .x(function(d) {
      return x(new Date(d[0]));;
    })
    .y0(function(d) {
      return y(d.y0);
    })
    .y1(function(d) {
      return y(d.y0 + d.y);
    });
  
  var svg = d3.select("body").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
    .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
  
  
  var b = [{
    data: [
      ["2016-01-20T05:31:17.000Z", 95.9, {}],
      ["2016-01-20T05:31:47.000Z", 95.9, {}],
      ["2016-01-20T05:32:17.000Z", 95.4, {}],
      ["2016-01-20T05:32:47.000Z", 96.1, {}],
      ["2016-01-20T05:33:17.000Z", 95.7, {}],
      ["2016-01-20T05:33:47.000Z", 95.9, {}],
      ["2016-01-20T05:34:17.000Z", 95.5, {}],
      ["2016-01-20T05:34:47.000Z", 95.9, {}],
      ["2016-01-20T05:35:17.000Z", 95.8, {}],
      ["2016-01-20T05:35:47.000Z", 95.9, {}],
      ["2016-01-20T05:36:17.000Z", 95.7, {}],
      ["2016-01-20T05:36:47.000Z", 95.7, {}],
      ["2016-01-20T05:37:17.000Z", 95.9, {}],
      ["2016-01-20T05:37:47.000Z", 95.5, {}],
      ["2016-01-20T05:38:17.000Z", 95.4, {}],
      ["2016-01-20T05:38:47.000Z", 95.8, {}],
      ["2016-01-20T05:39:17.000Z", 96.0, {}],
      ["2016-01-20T05:39:47.000Z", 96.1, {}],
      ["2016-01-20T05:40:17.000Z", 95.8, {}],
      ["2016-01-20T05:40:47.000Z", 96.0, {}],
      ["2016-01-20T05:41:17.000Z", 95.9, {}],
      ["2016-01-20T05:41:47.000Z", 94.9, {}],
      ["2016-01-20T05:42:17.000Z", 95.8, {}],
      ["2016-01-20T05:42:47.000Z", 95.9, {}],
      ["2016-01-20T05:43:17.000Z", 95.8, {}],
      ["2016-01-20T05:43:47.000Z", 96.0, {}],
      ["2016-01-20T05:44:17.000Z", 95.7, {}],
      ["2016-01-20T05:44:47.000Z", 96.0, {}],
      ["2016-01-20T05:45:17.000Z", 95.9, {}],
      ["2016-01-20T05:45:47.000Z", 96.0, {}],
      ["2016-01-20T05:46:17.000Z", 95.8, {}],
      ["2016-01-20T05:46:47.000Z", 96.0, {}],
      ["2016-01-20T05:47:17.000Z", 95.7, {}],
      ["2016-01-20T05:47:47.000Z", 96.2, {}],
      ["2016-01-20T05:48:17.000Z", 95.8, {}],
      ["2016-01-20T05:48:47.000Z", 95.9, {}],
      ["2016-01-20T05:49:17.000Z", 95.7, {}],
      ["2016-01-20T05:49:47.000Z", 95.9, {}],
      ["2016-01-20T05:50:18.000Z", 95.7, {}],
      ["2016-01-20T05:50:48.000Z", 95.8, {}],
      ["2016-01-20T05:51:18.000Z", 95.7, {}],
      ["2016-01-20T05:51:48.000Z", 95.9, {}],
      ["2016-01-20T05:52:18.000Z", 95.5, {}],
      ["2016-01-20T05:52:48.000Z", 95.9, {}],
      ["2016-01-20T05:53:18.000Z", 95.8, {}],
      ["2016-01-20T05:53:48.000Z", 95.9, {}],
      ["2016-01-20T05:54:18.000Z", 95.7, {}],
      ["2016-01-20T05:54:48.000Z", 95.9, {}],
      ["2016-01-20T05:55:18.000Z", 95.8, {}],
      ["2016-01-20T05:55:48.000Z", 95.8, {}],
      ["2016-01-20T05:56:18.000Z", 95.6, {}],
      ["2016-01-20T05:56:48.000Z", 95.7, {}],
      ["2016-01-20T05:57:18.000Z", 95.7, {}],
      ["2016-01-20T05:57:48.000Z", 95.8, {}],
      ["2016-01-20T05:58:18.000Z", 95.7, {}],
      ["2016-01-20T05:58:48.000Z", 95.7, {}],
      ["2016-01-20T05:59:18.000Z", 95.6, {}],
      ["2016-01-20T05:59:48.000Z", 95.8, {}],
      ["2016-01-20T06:00:18.000Z", 95.7, {}],
      ["2016-01-20T06:00:48.000Z", 95.7, {}],
      ["2016-01-20T06:01:18.000Z", 95.6, {}],
      ["2016-01-20T06:01:48.000Z", 95.7, {}],
      ["2016-01-20T06:02:18.000Z", 95.8, {}],
      ["2016-01-20T06:02:48.000Z", 95.8, {}],
      ["2016-01-20T06:03:18.000Z", 95.8, {}],
      ["2016-01-20T06:03:48.000Z", 95.8, {}],
      ["2016-01-20T06:04:18.000Z", 95.8, {}],
      ["2016-01-20T06:04:48.000Z", 95.8, {}],
      ["2016-01-20T06:05:18.000Z", 95.7, {}],
      ["2016-01-20T06:05:48.000Z", 95.7, {}]
    ],
    label: "a"
  }, {
    data: [
      ["2016-01-20T05:31:17.000Z", 95.9, {}],
      ["2016-01-20T05:31:47.000Z", 95.9, {}],
      ["2016-01-20T05:32:17.000Z", 95.4, {}],
      ["2016-01-20T05:32:47.000Z", 96.1, {}],
      ["2016-01-20T05:33:17.000Z", 95.7, {}],
      ["2016-01-20T05:33:47.000Z", 95.9, {}],
      ["2016-01-20T05:34:17.000Z", 95.5, {}],
      ["2016-01-20T05:34:47.000Z", 95.9, {}],
      ["2016-01-20T05:35:17.000Z", 95.8, {}],
      ["2016-01-20T05:35:47.000Z", 95.9, {}],
      ["2016-01-20T05:36:17.000Z", 95.7, {}],
      ["2016-01-20T05:36:47.000Z", 95.7, {}],
      ["2016-01-20T05:37:17.000Z", 95.9, {}],
      ["2016-01-20T05:37:47.000Z", 95.5, {}],
      ["2016-01-20T05:38:17.000Z", 95.4, {}],
      ["2016-01-20T05:38:47.000Z", 95.8, {}],
      ["2016-01-20T05:39:17.000Z", 96.0, {}],
      ["2016-01-20T05:39:47.000Z", 96.1, {}],
      ["2016-01-20T05:40:17.000Z", 95.8, {}],
      ["2016-01-20T05:40:47.000Z", 96.0, {}],
      ["2016-01-20T05:41:17.000Z", 95.9, {}],
      ["2016-01-20T05:41:47.000Z", 94.9, {}],
      ["2016-01-20T05:42:17.000Z", 95.8, {}],
      ["2016-01-20T05:42:47.000Z", 95.9, {}],
      ["2016-01-20T05:43:17.000Z", 95.8, {}],
      ["2016-01-20T05:43:47.000Z", 96.0, {}],
      ["2016-01-20T05:44:17.000Z", 95.7, {}],
      ["2016-01-20T05:44:47.000Z", 96.0, {}],
      ["2016-01-20T05:45:17.000Z", 95.9, {}],
      ["2016-01-20T05:45:47.000Z", 96.0, {}],
      ["2016-01-20T05:46:17.000Z", 95.8, {}],
      ["2016-01-20T05:46:47.000Z", 96.0, {}],
      ["2016-01-20T05:47:17.000Z", 95.7, {}],
      ["2016-01-20T05:47:47.000Z", 96.2, {}],
      ["2016-01-20T05:48:17.000Z", 95.8, {}],
      ["2016-01-20T05:48:47.000Z", 95.9, {}],
      ["2016-01-20T05:49:17.000Z", 95.7, {}],
      ["2016-01-20T05:49:47.000Z", 95.9, {}],
      ["2016-01-20T05:50:18.000Z", 95.7, {}],
      ["2016-01-20T05:50:48.000Z", 95.8, {}],
      ["2016-01-20T05:51:18.000Z", 95.7, {}],
      ["2016-01-20T05:51:48.000Z", 95.9, {}],
      ["2016-01-20T05:52:18.000Z", 95.5, {}],
      ["2016-01-20T05:52:48.000Z", 95.9, {}],
      ["2016-01-20T05:53:18.000Z", 95.8, {}],
      ["2016-01-20T05:53:48.000Z", 95.9, {}],
      ["2016-01-20T05:54:18.000Z", 95.7, {}],
      ["2016-01-20T05:54:48.000Z", 95.9, {}],
      ["2016-01-20T05:55:18.000Z", 95.8, {}],
      ["2016-01-20T05:55:48.000Z", 95.8, {}],
      ["2016-01-20T05:56:18.000Z", 95.6, {}],
      ["2016-01-20T05:56:48.000Z", 95.7, {}],
      ["2016-01-20T05:57:18.000Z", 95.7, {}],
      ["2016-01-20T05:57:48.000Z", 95.8, {}],
      ["2016-01-20T05:58:18.000Z", 95.7, {}],
      ["2016-01-20T05:58:48.000Z", 95.7, {}],
      ["2016-01-20T05:59:18.000Z", 95.6, {}],
      ["2016-01-20T05:59:48.000Z", 95.8, {}],
      ["2016-01-20T06:00:18.000Z", 95.7, {}],
      ["2016-01-20T06:00:48.000Z", 95.7, {}],
      ["2016-01-20T06:01:18.000Z", 95.6, {}],
      ["2016-01-20T06:01:48.000Z", 95.7, {}],
      ["2016-01-20T06:02:18.000Z", 95.8, {}],
      ["2016-01-20T06:02:48.000Z", 95.8, {}],
      ["2016-01-20T06:03:18.000Z", 95.8, {}],
      ["2016-01-20T06:03:48.000Z", 95.8, {}],
      ["2016-01-20T06:04:18.000Z", 95.8, {}],
      ["2016-01-20T06:04:48.000Z", 95.8, {}],
      ["2016-01-20T06:05:18.000Z", 95.7, {}],
      ["2016-01-20T06:05:48.000Z", 95.7, {}]
    ],
    label: "b"
  }]
  
  
  
  
  var layers = stack(b);
  
  var ary = [];
  layers.forEach(function(d) {
    ary.push(d.data)
  })
  
  x.domain(d3.extent(d3.merge(ary), function(d) {
    return new Date(d[0]);
  }));
  y.domain([0, d3.max(d3.merge(ary), function(d) {
    return d.y0 + d.y;
  })]);
  
  
  svg.selectAll(".layer")
    .data(layers)
    .enter().append("path")
    .attr("class", "layer")
    .attr("d", function(d) {
      return area(d.data);
    })
    .style("fill", function(d, i) {
      return z(i);
    });
  
  svg.append("g")
    .attr("class", "x axis")
    .attr("transform", "translate(0," + height + ")")
    .call(xAxis);
  
  svg.append("g")
    .attr("class", "y axis")
    .call(yAxis);</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body {
    font: 10px sans-serif;
  }
  .axis path,
  .axis line {
    fill: none;
    stroke: #000;
    shape-rendering: crispEdges;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>NOTE:</strong> Data values are dynamic, so y-axis tick values are not fixed. Please help me find a solution which can be applicable on any data.</p>