Built with blockbuilder.org
Last active
February 8, 2016 05:00
-
-
Save xsurge83/3e88403100f39ecba136 to your computer and use it in GitHub Desktop.
fresh block
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> | |
<head> | |
<meta charset="utf-8"> | |
<script src="//d3js.org/d3.v4.0.0-alpha.4.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
svg { width:100%; height: 100% } | |
body { | |
font: 10px sans-serif; | |
} | |
.axis path, | |
.axis line { | |
fill: none; | |
stroke: #000; | |
shape-rendering: crispEdges; | |
} | |
.area { | |
fill: lightsteelblue; | |
} | |
.line { | |
fill: none; | |
stroke: steelblue; | |
stroke-width: 1.5px; | |
} | |
.dot { | |
fill: white; | |
stroke: steelblue; | |
stroke-width: 1.5px; | |
} | |
</style> | |
</head> | |
<body> | |
<script> | |
var data = d3.range(40).map(function(i) { | |
return i % 5 ? {x: i / 39, y: (Math.sin(i / 3) + 2) / 4} : null; | |
}); | |
var margin = {top: 40, right: 40, bottom: 40, left: 40}, | |
width = 960 - margin.left - margin.right, | |
height = 500 - margin.top - margin.bottom; | |
var x = d3.scaleLinear() | |
.range([0, width]); | |
var y = d3.scaleLinear() | |
.range([height, 0]); | |
var line = d3.svg.line() | |
// .defined(function(d) { return d; }) | |
.x(function(d) { return x(d.x); }) | |
.y(function(d) { return y(d.y); }); | |
var area = d3.area() | |
.defined(line.defined()) | |
.x(line.x()) | |
.y1(line.y()) | |
.y0(y(0)); | |
var svg = d3.select("body").append("svg") | |
.datum(data) | |
.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("path") | |
.attr("class", "area") | |
.attr("d", area); | |
svg.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + height + ")") | |
.call(d3.axisBottom().scale(x)); | |
svg.append("g") | |
.attr("class", "y axis") | |
.call(d3.axisLeft().scale(y)); | |
svg.append("path") | |
.attr("class", "line") | |
.attr("d", line); | |
svg.selectAll(".dot") | |
.data(data.filter(function(d) { return d; })) | |
.enter().append("circle") | |
.attr("class", "dot") | |
.attr("cx", line.x()) | |
.attr("cy", line.y()) | |
.attr("r", 3.5); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment