Skip to content

Instantly share code, notes, and snippets.

Last active October 6, 2023 20:55
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Rotated Axis Labels
license: gpl-3.0

This example demonstrates how to rotate axis labels by 90° using post-selection. After the axis is rendered, the text label elements are selected, and then attributes on the elements are modified to customize the label appearance.

<!DOCTYPE html>
<meta charset="utf-8">
.axis text {
font: 10px sans-serif;
.axis line,
.axis path {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
<script src="//"></script>
var margin = {top: 250, right: 40, bottom: 250, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - - margin.bottom;
var x = d3.time.scale()
.domain([new Date(2012, 0, 1), new Date(2013, 0, 1)])
.range([0, width]);
var xAxis = d3.svg.axis()
var svg ="body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + + margin.bottom)
.attr("transform", "translate(" + margin.left + "," + + ")");
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.attr("y", 0)
.attr("x", 9)
.attr("dy", ".35em")
.attr("transform", "rotate(90)")
.style("text-anchor", "start");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment