d3 / d3-axis

Human-readable reference marks for scales.

Home Page:https://d3js.org/d3-axis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Right-align tick text in axisRight() ?

tippmar opened this issue · comments

Is there a way to right-align the tick text when creating a right axis via axisRight()?

I'm currently rendering a right axis on my graph like so:

  root
    .attr("class", "y gap-axis")
    .attr("margin-top", margin.top)
    .attr("transform", `translate(${width})`)
    .call(
      d3.axisRight(barYScale)
        .tickPadding(-1),
    );
}

and I get results like so:
image
but I want the numbers to be right-aligned.

You can use d3.axisLeft if you want right-aligned ticks. Sometimes I use an axisRight on the left side of the plot, as in this contour plot example.

Alternatively, you can select the elements generated by the axis and modify them however you like, as in the styled axes example.