/
ch6-2.html
69 lines (59 loc) · 1.94 KB
/
ch6-2.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<html>
<head>
<title>My First SVG Path using D3</title>
<meta name="description" content="Practical D3">
<meta name="author" content="Tarek Amr, @gr33ndata">
</head>
<body>
<svg width="200" height="200" id="fun-drawing-area" style="background: #EEE">
</svg>
</body>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script type="text/javascript">
var fda = d3.select("#fun-drawing-area");
data = [0, 25, 50, 75, 100, 125, 150, 175, 200];
var gen = d3.svg.line()
.x(function(d){
return d;
})
.y(function(d){
if (d % 50 == 0){
return 150;
} else {
return 50;
}
})
.interpolate('monotone');
var lineGraph = fda.append("path")
.attr("d", gen(data))
.attr("stroke", "black")
.attr("stroke-width", 2)
.attr("fill", "#EEE");
// Function to be used by gen2()
// var fx = function(x){
// if (x % 50 == 0){
// return 150;
// } else {
// return 50;
// }
// }
// Another generator, gen2
// var gen2 = d3.svg.line()
// .x(function(d){
// return d;
// })
// .y(function(d){
// return fx(d);
// });
// Try gen2 this time instead of gen
// var lineGraph = fda.append("path")
// .attr("d", gen2(data))
// .attr("stroke", "black")
// .attr("stroke-width", 2)
// .attr("fill", "#EEE");
// Just label explaining which interpolate is being used
fda.append("text")
.attr("x", 20).attr("y", 30)
.text("interpolate('monotone')");
</script>
<html>