Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3 axis tick alignment

Tags:

d3.js

I have a d3 bar chart with, and the axis tick marks are centered below the bars (as I would expect). In this case, I would actually like to left align the axis ticks and have the ticks under the left edge of the bar. Is that possible?enter image description here

EDIT: Javascript for constructing the axis

// note width is just the width of the chart
var xScale = d3.scale.ordinal().rangeRoundBands([0,width], .1); 
var xAxis = d3.svg.axis().scale(xScale).orient("bottom");
like image 214
Jeff Storey Avatar asked Nov 30 '12 23:11

Jeff Storey


1 Answers

here is an example of left aligning the ticks.

http://bl.ocks.org/mbostock/6186172

the idea is that after you create the ticks you collect them and aligne them:

svg.append("g")
    .attr("class", "x axis")
    .attr("transform", "translate(0," + height + ")")
    .call(xAxis)
  .selectAll("text")
    .attr("y", 6)
    .attr("x", 6)
    .style("text-anchor", "start");
like image 121
Raven Avatar answered Sep 20 '22 18:09

Raven