I also posted this question on the Google Group https://groups.google.com/forum/?fromgroups#!topic/d3-js/DYiVeC544ws, but saw that it prefers that help questions are asked here. I’m just having trouble shifting the y-axis to the left of my graph to so that it does not get in the way of the first column. I provided an image on the google group so you can see what I’m talking about.
The code to create the axis is as follows:
var MARGINS = {top: 20, right: 20, bottom: 20, left: 60}; // margins around the graph
var xRange = d3.scale.linear().range([MARGINS.left, width - MARGINS.right]), // x range function
yRange = d3.scale.linear().range([height - MARGINS.top, MARGINS.bottom]), // y range function
xAxis = d3.svg.axis().scale(xRange).tickSize(16).tickSubdivide(true), // x axis function
yAxis = d3.svg.axis().scale(yRange).tickSize(10).orient("right").tickSubdivide(true); // y axis function
// create the visualization chart
var vis = d3.select("#chart")
.append("svg")
.attr("width", width)
.attr("height", height + margin);
// add in the x axis
vis.append("svg:g") // container element
.attr("class", "x axis") // so we can style it with CSS
.attr("transform", "translate(0," + height + ")") // move into position
// .call(xAxis); // add to the visualisation
// add in the y axis
vis.append("svg:g") // container element
.attr("class", "y axis") // so we can style it with CSS
.call(yAxis); // add to the visualisation
Use the transform attribute to shift the y-axis, just as you did for the x-axis. For example:
This is only necessary when using right orientation. When the axis is oriented to the left, the default positioning is typically fine.
Also, I recommend using the following convention for margins:
widthandheightas the inner width and height.For example:
If you prefer, you could also store the inner and outer dimensions, e.g.,
Here’s a visual explanation of the convention: