-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph_analysis.php
132 lines (109 loc) · 2.7 KB
/
graph_analysis.php
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!-- From this... -->
<!DOCTYPE html>
<html>
<head>
<style>
body{
text-align: center;
}
svg{
padding-left:520px;
}
</style>
</head>
<body>
<script src='http://d3js.org/d3.v3.min.js'></script>
<script>
var nums = [80, 53, 125, 90, 28, 97];
var nums2 =[80, 53, 125, 90, 28, 97];
var svg = d3.select('body').append('svg')
.attr('height', 700)
.attr('width', 700);
var bars = svg.selectAll('rect')
.data(nums);
var circ = svg.selectAll('circle')
.data(nums2);
var text = svg.selectAll('text')
.data(nums2);
// var poly = svg.selectAll('polygon')
// .data(nums2);
bars.enter().append('rect');
circ.enter().append('circle');
text.enter().append('text');
// poly.enter().append('polygon');
d3.selectAll('rect','circle')
.attr('width', 20)
.attr('height', 20);
d3.selectAll('text')
.attr('width', 20)
.attr('height', 20);
//d represents the current data point, and i the current index
bars.attr('x', function(d, i) {
return 70*i;
});
circ.attr('cx', function(d, i) {
return 72*i;
});
circ.attr('r', function(d, i) {
return .2*d;
});
circ.attr('fill', function(d, i) {
return 'green';
});
text.attr('dy', function(d,i){
return '.3em';
});
text.attr('x', function(d,i){
return '50%';
});
text.attr('y', function(d,i){
return '50%';
});
text.attr('text-anchor','middle');
// line.attr('y2', function(d,i){
// return 5 * d;
// });
// line.attr('stroke', function(d,i){
// return 'black';
// });
// line.attr('stroke-width', function(d,i){
// return .8 * d;
// });
// poly.attr('x', function(d, i) {
// return 80*i;
// });
// poly.attr('stroke-width', function(d, i) {
// return .03*d;
// });
// poly.attr('stroke', function(d, i) {
// return 'black';
// });
// poly.attr('points', function(d, i) {
// return '05,30 15,10 25,30';
// });
// poly.attr('fill', function(d, i) {
// return 'yellow';
// });
//this binds the data from nums array to the height attr
bars.attr('height', function(d, i) {
return d;
});
circ.attr('height', function(d, i) {
return d;
});
//this will invert the graph so it's upright
bars.attr('y', function(d, i) {
return 700 - d;
});
circ.attr('cy', function(d, i) {
return 600 - d;
});
circ.attr('text', function(d, i) {
return d;
});
// poly.attr('y', function(d, i) {
// return 600 - d;
// });
</script>
</body>
</html>