1.) This is controlled by the domain of your weights. Since your domains are set in the data volume, the axis starts there. A simple fix is ββto increase your domain to + - N percent of the range. In addition, I recommend removing .nice() , as you just end up fighting it to control the range.
// get extents and range var xExtent = d3.extent(data, function(d) { return d.grade; }), xRange = xExtent[1] - xExtent[0], yExtent = d3.extent(data, function(d) { return d.bin; }), yRange = yExtent[1] - yExtent[0]; // set domain to be extent +- 5% x.domain([xExtent[0] - (xRange * .05), xExtent[1] + (xRange * .05)]); y.domain([yExtent[0] - (yRange * .05), yExtent[1] + (yRange * .05)]);
2.) This is controlled by the outerTickSize option. Just set it to zero.
var yAxisLeft = d3.svg.axis() .scale(y) .ticks(yTicks) .outerTickSize(0) //<-- set to zero .orient("left");
Full example working code:
<!DOCTYPE html> <html> <meta charset="utf-8"> <head> <title>Proportion of Students Suspended <body></body> Grade</title> <style type="text/css"> body { font: 10px Helvetica; } .axis path, .axis line { fill: none; stroke: #000; shape-rendering: crispEdges; } </style> </head> <body> <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> <script type="text/javascript"> </script> </body> </html>
Mark
source share