-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
67 lines (51 loc) · 1.62 KB
/
test.html
File metadata and controls
67 lines (51 loc) · 1.62 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
</style>
</head>
<body>
<div class="chart"><svg></svg></div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var data = [{"data": 1, "key": 1}, {"data": 4, "key": 1}, {"data": 5, "key": 1}, {"data": 51, "key": ''}, {"data": 24, "key": 1}, {"data": 8, "key": 1}, {"data": 12, "key": 1}, {"data": 1, "key": 1}, {"data": 1, "key": 1}, {"data": 20, "key": 1}];
var chart = d3.select('.chart svg');
// Add all bars to the chart.
var rects = chart
.selectAll('rect')
.data(data, function(d) { return (d.key +''+ d.data); })
.enter()
createRectangles(rects);
// Remove bars after a short delay.
d3.selectAll('g')
.data([{"data": 5, "key": 1}, {"data": 51, "key": ''}], function(d) { return (d.date +''+ d.key); })
.order()
.exit()
.transition()
.delay(3000)
.remove();
// Separate out the creation from the data selection.
function createRectangles(rectang){
// Create a group with a rectangle
rectang.append("g").append('rect')
.attr("class", "rectangle")
.attr("stroke", "black")
.attr("stroke-width","1px")
.attr("fill","none")
.attr("x", 0)
.attr("y", function(d, i) { return 25 * i; } )
.attr("width", function(d) { return 22 * d.data; } )
.attr("height", "20");
// Add text to the group
d3.selectAll("g")
.append("text")
.text(function(d){ return d.data; })
.attr("x", 2)
.attr("y", function(d, i) { return 25 * i + 16; } )
.attr("fill", "steelblue");
return rects;
}
</script>
</body>
</html>