Created
May 2, 2012 05:06
-
-
Save webmonarch/2573905 to your computer and use it in GitHub Desktop.
area-d3-raphael-example.html
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> | |
<!-- From https://github.com/webmonarch/d3/tree/raphael-compat/examples/area --> | |
<meta charset="utf-8"> | |
<style> | |
body { | |
font: 10px sans-serif; | |
} | |
.axis path, .axis line { | |
fill: none; | |
stroke: #000; | |
shape-rendering: crispEdges; | |
} | |
.area { | |
stroke: none; | |
fill: lightsteelblue; | |
} | |
.line { | |
fill: none; | |
stroke: steelblue; | |
stroke-width: 1.5px; | |
} | |
.dot { | |
fill: white; | |
stroke: steelblue; | |
stroke-width: 1.5px; | |
} | |
</style> | |
<body> | |
<!--[if lte IE 8]> | |
<script type="text/javascript" src="../../lib/sizzle/sizzle.js"></script> | |
<script type="text/javascript" src="../../lib/ie8/compat.js"></script> | |
<![endif]--> | |
<script type="text/javascript" src="../../lib/raphael/raphael.js"></script> | |
<script src="../../d3.v2.js"></script> | |
<script> | |
var data = d3.range(40).map(function(i) { | |
return {x: i / 39, y: (Math.sin(i / 3) + 2) / 4}; | |
}); | |
var margin = {top: 10.5, right: 10.5, bottom: 20.5, left: 40.5}, | |
width = 960 - margin.left - margin.right, | |
height = 500 - margin.top - margin.bottom; | |
var x = d3.scale.linear() | |
.domain([0, 1]) | |
.range([0, width]); | |
var y = d3.scale.linear() | |
.domain([0, 1]) | |
.range([height, 0]); | |
var xAxis = d3.raphael.axis() | |
.top(height) | |
.scale(x) | |
.orient("bottom"); | |
var yAxis = d3.raphael.axis() | |
.scale(y) | |
.orient("left"); | |
var line = d3.svg.line() | |
.x(function(d) { return x(d.x); }) | |
.y(function(d) { return y(d.y); }); | |
var area = d3.svg.area() | |
.x(line.x()) | |
.y1(line.y()) | |
.y0(y(0)); | |
var paper = new Raphael(document.body, width + margin.left + margin.right, height + margin.top + margin.bottom); | |
var svg = d3.raphael(paper) | |
.datum(data); | |
paper.setStart(); | |
svg.append("path") | |
.attr("class", "area") | |
.attr("d", area); | |
svg.append("path") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + height + ")") | |
.call(xAxis); | |
svg.append("path") | |
.attr("class", "y axis") | |
.call(yAxis); | |
svg.append("path") | |
.attr("class", "line") | |
.attr("d", line); | |
svg.selectAll(".dot") | |
.data(data.filter(function(d) { return d.y; })) | |
.enter().append("circle") | |
.attr("class", "dot") | |
.attr("cx", line.x()) | |
.attr("cy", line.y()) | |
.attr("r", 3.5); | |
paper.setFinish().transform(['t', margin.left, margin.top]); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment