Created
November 19, 2015 21:27
-
-
Save d3byex/f32adf3e0dbd850f0ebb to your computer and use it in GitHub Desktop.
D3byEX 4.9: Axis with Inverted Labels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<meta name="description" content="D3byEX 4.9" /> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<script> | |
var data = [55, 44, 30, 23, 17, 14, 16, 25, 41, 61, 85, | |
101, 95, 105, 114, 150, 180, 210, 125, 100, 71, | |
75, 72, 67]; | |
var maxValue = d3.max(data); | |
var width = 500, height = maxValue; | |
var svg = d3.select('body') | |
.append('svg') | |
.attr({ width: width, height: height }); | |
var scale = d3.scale | |
.linear() | |
.domain([maxValue, 0]) | |
.range([0, maxValue]); | |
var axis = d3.svg.axis() | |
.orient('left') | |
.scale(scale); | |
var axisGroup = svg.append('g') | |
.attr('transform', 'translate(50, 0)'); | |
var axisNodes = axisGroup.call(axis); | |
var domain = axisNodes.selectAll('.domain'); | |
domain.attr({ | |
fill: 'none', | |
'stroke-width': 1, | |
stroke: 'black' | |
}); | |
var ticks = axisNodes.selectAll('.tick line'); | |
ticks.attr({ | |
fill: 'none', | |
'stroke-width': 1, | |
stroke: 'black' | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment