-
Notifications
You must be signed in to change notification settings - Fork 1
/
index3.html
110 lines (92 loc) · 3.22 KB
/
index3.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
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
<!DoCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Amount of Time Spent with TA</title>
<link data-require="normalize@*" data-semver="3.0.1" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.min.css" />
<style>
#chart {
height: 700px;
margin: 0 auto; /* NEW */
position: relative;
width: 700px;
}
.legend {
font-size: 12px sans-serif;
}
rect {
stroke-width: 2;
}
h1{
font-size: 18px;
text-align:center;
font-family: Verdana, sans-serif;
}
</style>
</head>
<body>
<h1>Amount of Time Spent Receiving Help</h1>
<div id="chart"></div>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.4.6/d3.min.js" data-semver="3.4.6" data-require="d3@*"></script>
<script>
(function(d3) {
'use strict';
// REMOVED var data = ...
var width = 700;
var height = 700;
var radius = Math.min(width, height) / 2;
var donutWidth = 75;
var legendRectSize = 18;
var legendSpacing = 4;
var color = d3.scale.category20b();
var svg = d3.select('#chart')
.append('svg')
.attr('width', width)
.attr('height', height)
.append('g')
.attr('transform', 'translate(' + (width / 2) +
',' + (height / 2) + ')');
var arc = d3.svg.arc()
.innerRadius(radius - donutWidth)
.outerRadius(radius);
var pie = d3.layout.pie()
.value(function(d) { return d.timeCount; })
.sort(null);
d3.json('getdata2.php', function(error, dataset) { // NEW
dataset.forEach(function(d) { // NEW
d.timeCount = +d.timeCount; // NEW
}); // NEW
var path = svg.selectAll('path')
.data(pie(dataset))
.enter()
.append('path')
.attr('d', arc)
.attr('fill', function(d, i) {
return color(d.data.studentName);
});
var legend = svg.selectAll('.legend')
.data(color.domain())
.enter()
.append('g')
.attr('class', 'legend')
.attr('transform', function(d, i) {
var height = legendRectSize + legendSpacing;
var offset = height * color.domain().length / 2;
var horz = -2 * legendRectSize;
var vert = i * height - offset;
return 'translate(' + horz + ',' + vert + ')';
});
legend.append('rect')
.attr('width', legendRectSize)
.attr('height', legendRectSize)
.style('fill', color)
.style('stroke', color);
legend.append('text')
.attr('x', legendRectSize + legendSpacing)
.attr('y', legendRectSize - legendSpacing)
.text(function(d) { return d; });
}); // NEW
})(window.d3);
</script>
</body>
</html>