Last active
December 21, 2015 07:19
-
-
Save brickgao/6270713 to your computer and use it in GitHub Desktop.
D3.js Learning
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
<!--A bar Chart Part1-sample1--> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>A bar Chart Part 1</title> | |
<style type="text/css"> | |
body { | |
height: 100%; | |
} | |
.chart div { | |
font: 10px sans-serif; | |
background-color: steelblue; | |
text-align: right; | |
padding: 3px; | |
margin: 1px; | |
color: white; | |
} | |
</style> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
</head> | |
<body> | |
</body> | |
<script type="text/javascript"> | |
var data = [4, 8, 15, 16, 23, 42]; | |
var chart = d3.select("body").append("div") | |
.attr("class", "chart"); | |
chart.selectAll("div") | |
.data(data) | |
.enter().append("div") | |
.style("width", function(d){ return d * 10 + "px"; }) | |
.text(function(d) { return d; }); | |
</script> | |
</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
<!--A bar Chart Part1-sample2--> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>A bar Chart Part 1</title> | |
<style type="text/css"> | |
body { | |
height: 100%; | |
} | |
.chart div { | |
font: 10px sans-serif; | |
background-color: steelblue; | |
text-align: right; | |
padding: 3px; | |
margin: 1px; | |
color: white; | |
} | |
</style> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
</head> | |
<body> | |
</body> | |
<script type="text/javascript"> | |
var data = [4, 8, 15, 16, 23, 42]; | |
var chart = d3.select("body").append("div") | |
.attr("class", "chart"); | |
var x = d3.scale.linear() | |
.domain([0, d3.max(data)]) | |
.range(["0px", "600px"]); | |
chart.selectAll("div") | |
.data(data) | |
.enter().append("div") | |
.style("width", x) | |
.text(String); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment