-
-
Save timelyportfolio/5381446 to your computer and use it in GitHub Desktop.
forked from Mike Bostock to begin d3 replacement for PerformanceSummary
This file contains hidden or 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> | |
<meta charset="utf-8"> | |
<style> | |
body { | |
font: 10px sans-serif; | |
} | |
.axis path { | |
display: none; | |
} | |
.axis line { | |
shape-rendering: crispEdges; | |
stroke: #000; | |
} | |
.axis .minor line { | |
stroke: #777; | |
stroke-dasharray: 2,2; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var margin = {top: 20, right: 0, bottom: 20, left: 0}, | |
width = 960 - margin.left - margin.right, | |
height = 500 - margin.top - margin.bottom; | |
var formatNumber = d3.format(".1f"); | |
var y = d3.scale.linear() | |
.domain([0, 2e6]) | |
.range([height, 0]); | |
var x = d3.time.scale() | |
.domain([new Date(2010, 7, 1), new Date(2012, 7, 1)]) | |
.range([0, width]); | |
var xAxis = d3.svg.axis() | |
.scale(x) | |
.ticks(d3.time.years) | |
.orient("bottom"); | |
var yAxis = d3.svg.axis() | |
.scale(y) | |
.tickSize(width) | |
.tickFormat(formatCurrency) | |
.orient("right"); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width + margin.left + margin.right) | |
.attr("height", height + margin.top + margin.bottom) | |
.append("g") | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
svg.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + height + ")") | |
.call(xAxis); | |
var gy = svg.append("g") | |
.attr("class", "y axis") | |
.call(yAxis); | |
gy.selectAll("g").filter(function(d) { return d; }) | |
.classed("minor", true); | |
gy.selectAll("text") | |
.attr("x", 4) | |
.attr("dy", -4); | |
function formatCurrency(d) { | |
var s = formatNumber(d / 1e6); | |
return d === y.domain()[1] | |
? "$" + s + " million" | |
: s; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment