-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex3.html
More file actions
74 lines (65 loc) · 1.24 KB
/
index3.html
File metadata and controls
74 lines (65 loc) · 1.24 KB
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
70
71
72
73
74
<!DOCTYPE html>
<meta charset="utf-8"
<html>
<head>
<style>
svg {
width: 960px;
height: 500px;
border: 1px solid gray;
}
</style>
</head>
<body>
<svg></svg>
<script src="scripts/d3.js"></script>
<script src="scripts/d3.min.js"></script>
<script src="scripts/jquery-1.12.0.js"></script>
<script>
var svg = d3.select("svg");
var data = [{x:0, y:8},
{x:10, y:22},
{x:20, y:20},
{x:30, y:80},
{x:40, y:34},
{x:50, y:54},
{x:60, y:54},
{x:70, y:9},
{x:80, y:128},
{x:90, y:12}
];
var line = d3.svg.line()
.x(function(d) {
return d.x;
})
.y(function(d) {
return d.y;
});
var tx=150;
var ty=250;
var group = svg.append("g").
attr("transform", "translate("+[tx,ty]+")")
var path = group.selectAll("path")
.data([data])
.enter()
.append("path")
.attr({
d: line,
fill: "none",
stroke: "#0a0a0a"
})
var text = group.append("text")
.attr("transform","translate("+[-1,-13]+")")
.text(line(data))
svg.on("click", function(){
var p = d3.mouse(this);
data.push({
x:p[0]-tx,
y:p[1]-ty
})
path.attr("d", line)
text.text(line(data))
})
</script>
<body>
</html>