-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample-dashboard3.html
159 lines (116 loc) · 3.84 KB
/
sample-dashboard3.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
index.html#
<!DOCTYPE html>
<html ng-app="simpleD3DashboradApp">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Testing Pie Chart</title>
<!--<script type="text/javascript" src="d3/d3.v2.js"></script>-->
<script src="http://d3js.org/d3.v2.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<!-- Note: I made good use of the sample code provided by the D3JS community and extended it to fit my needs to create this simple dashboard -->
<style type="text/css">
</style>
</head>
<body ng-controller="simpleCtrl">
<pic-chart data="charts"
>
</pie-chart>
category: {{name}}
<script type="text/javascript">
var sApp = angular.module("simpleD3DashboradApp", [])
.controller("simpleCtrl", function($scope,$http){
$scope.name = "Cyril";
// Your code for $http connection
//create function to set the default data set to load
$scope.getData = function(){
$http.get('simple-data.json').success(function(data) {
console.log(data);
$scope.charts = data;
});
}
//});
//invoke data function
$scope.getData();
})
// directive for bar chart
.directive('pieChart', function(){
function link(scope,el,attrs){
var el =el[0];
var margin = {top: 70, right: 20, bottom: 50, left: 40},
w = 720 - margin.left - margin.right,
h = 600 - margin.top - margin.bottom;
var color = d3.scale.ordinal()
.range(["#ffc87c", "#dda66b"]);
//.range(function(d) { return d3.hsl(d % x / x * 360, 1, Math.floor(d / x) / y); })
//.style("fill", function(d) { return d3.hsl(d % x / x * 360, 1, Math.floor(d / x) / y); })
var radius = Math.min(w, h) / 2;
var svg = d3.select(el).append("svg")
.attr("width", w + margin.left + margin.right)
.attr("height", h + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" +(w/2+margin.left)+
"," +(h/2+margin.top)+ ")");
/*var title = d3.select("svg").append("g")
.attr("transform", "translate(" +margin.left+ ", " +margin.top+ ")")
.attr("class", "title");
title.append("text")
.attr("x", (w / 2))
.attr("y", -30 )
.attr("text-anchor", "middle")
.style("font-size", "22px")
.text("A donut chart");
*/
var arc1 = d3.svg.arc()
.outerRadius(0.6 * radius)
.innerRadius(0.3 * radius);
var arc2 = d3.svg.arc()
.outerRadius(0.9 * radius )
.innerRadius(0.6 * radius );
var arc3 = d3.svg.arc()
.outerRadius(1.2 * radius )
.innerRadius(0.9 * radius );
scope.$watch("data", function(data){
var data = scope.data;
if(!scope.data){
return
}
/*
{
"level1": [
{
"category": "Rice",
"count1": 14,
"count2": 10
},
*/
var pie = d3.layout.pie()
.sort(null)
.value(function(d) { return d.measure; });
var g = svg.selectAll(".arc1")
.data(pie(data.dataset))
.enter().append("g")
.attr("class", "arc1");
g.append("path")
.attr("d", arc1)
.style("fill", function(d) { return color(d.data.category); });
g.append("text")
.attr("transform", function(d) {
return "translate(" + arc1.centroid(d) + ")"; })
.attr("dy", ".35em")
.style("text-anchor", "middle")
.text(function(d) { return d.data.measure; });
}, true);
}
return{
link: link,
restrict:'EA',
scope:{
data: '=',
width: '=',
height: '='
}
}
});
</script>
</body>
</html>