-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbarchart2.html
42 lines (34 loc) · 1.23 KB
/
barchart2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Barchart example</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body>
<h3>Barchart Example Two</h3>
<p>For our second example, we are moving from the synthetic data to data stored in a csv file. Again, view the source for the code and comments.</p>
<script type="text/javascript">
var width = 400;
var height = 200;
var chart = d3.select("body")
.append("svg")
.attr({"width": width, "height":height});
// The big difference here is that we are fetching a remote csv file with d3.csv
// d3.csv will fetch the file, parse it for us, and then call the function we provide
// with the parsed data when it is ready.
// Note that this is asynchronous, so don't put anything after this call that relies
// on the data being fetched.
d3.csv("http://www.cs.middlebury.edu/~candrews/classes/infovis/data/drwho.csv",function(dataset){
chart.selectAll("rect")
.data(dataset)
.enter()
.append("rect")
.attr({"x":function(d,i){return i*10;},
"y":function(d){return height- +d.companions;},
"width":9,
"height":function(d){return +d.companions;}});
});
</script>
</body>
</html>