JavaScript In D3 v4, how do I align axes appropriately?

I am using D3 v4. I have a bar graph created with an x-axis using scaleBand(). Now, I have created a y-axis but my issue is that no matter how I position it, it is cutting into the actual bars of the graph.

enter image description here

At the top of my JS file, I have:

var width = 350; var height = 300;

Then, the part where I actually create the Y-axis:

var y = d3.scaleLinear()
      .domain([0, 300000])
      .rangeRound([height, 0]);

var yAxis = d3.axisRight(y);
            yAxis.ticks(6);

chart.append("g")
     .attr("class", "y axis")
     .attr("transform", "translate(" + (width - dist_from_right) + ", 0)")
     .call(yAxis);

As you can see from the picture, the axis stretches the entirety of the height of the SVG, from bottom to top meaning that half of the 0 gets cut off and half off the 300,000 gets cut off.

First question: how do I "squish" (or scale) the y-axis so that it displays within the confines of the SVG?

Next, I want to translate the y-axis so that it is not cutting into my red bar. If I try to use the transform attribute, I can push the axis far to the right of the SVG borders but that means the numbers are off the SVG boundary. I've also tried to increase the width variable but that does nothing because it just stretches out the x-axis proportionally.

Second question: how do I move the y-axis so that it is not cutting into the x-axis and red bar and also remains visible in the SVG window?

Thanks!

Answer:1

I'm using casperJS to try to get a screenshot of a DOM element using captureSelector, but the quality of the screenshot is really poor, but when capturing full screenshot using capture it works ...

I'm using casperJS to try to get a screenshot of a DOM element using captureSelector, but the quality of the screenshot is really poor, but when capturing full screenshot using capture it works ...

I am developing a windows desktop application using node.js and backbone.js. I want to perform an action when the user closes the app by clicking on the close button on the title bar or right clicking ...

I am developing a windows desktop application using node.js and backbone.js. I want to perform an action when the user closes the app by clicking on the close button on the title bar or right clicking ...

For some reaon, I cannot use nested div, and I m trying to toggle a tree of divs Div id contains any string except - <div class="tree"> <div id="a">id=a click to toggle child</div&...

For some reaon, I cannot use nested div, and I m trying to toggle a tree of divs Div id contains any string except - <div class="tree"> <div id="a">id=a click to toggle child</div&...

I don't want to use the default, + icon, to expand the row. Clicking anywhere on the row should expand it. I tried this: HTML <div ui-grid="gridOptions" ui-grid-expandable class="grid"> ...

I don't want to use the default, + icon, to expand the row. Clicking anywhere on the row should expand it. I tried this: HTML <div ui-grid="gridOptions" ui-grid-expandable class="grid"> ...

  1. ui grid expandable grid example
  2. expandable grid ui-grid