-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·107 lines (104 loc) · 3.21 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="vendor/novus/nvd3/build/nv.d3.css" rel="stylesheet" type="text/css">
<script src="vendor/mbostock/d3/d3.min.js" charset="utf-8"></script>
<script src="vendor/novus/nvd3/build/nv.d3.js"></script>
<script src="vendor/novus/nvd3/test/stream_layers.js"></script>
<style>
text {
font: 12px sans-serif;
}
svg {
display: block;
float: left;
height: 350px !important;
width: 350px !important;
}
html, body {
margin: 0px;
padding: 0px;
height: 100%;
width: 100%;
}
</style>
</head>
<body class='with-3d-shadow with-transitions'>
<svg id="test1" class="mypiechart"></svg>
<svg id="test2" class="mypiechart"></svg>
<script>
var testdata = [
{key: "One", y: 5, color: "#5F5"},
{key: "Two", y: 2},
{key: "Three", y: 9},
{key: "Four", y: 7},
{key: "Five", y: 4},
{key: "Six", y: 3},
{key: "Seven", y: 0.5}
];
var testdata2 = [
{key: "One", y: 5},
{key: "Two", y: 2},
{key: "Three", y: 9},
{key: "Four", y: 7},
{key: "Five", y: 4},
{key: "Six", y: 3},
{key: "Seven", y: 0.5}
];
var height = 350;
var width = 350;
nv.addGraph(function() {
var chart = nv.models.pieChart()
.x(function(d) { return d.key })
.y(function(d) { return d.y })
.width(width)
.height(height);
d3.select("#test1")
.datum(testdata2)
.transition().duration(1200)
.attr('width', width)
.attr('height', height)
.call(chart);
// update chart data values randomly
setInterval(function() {
testdata2[0].y = Math.floor(Math.random() * 10);
testdata2[1].y = Math.floor(Math.random() * 10);
chart.update();
}, 4000);
return chart;
});
nv.addGraph(function() {
var chart = nv.models.pieChart()
.x(function(d) { return d.key })
.y(function(d) { return d.y })
//.labelThreshold(.08)
//.showLabels(false)
.color(d3.scale.category20().range().slice(8))
.growOnHover(false)
.labelType('value')
.width(width)
.height(height);
// make it a half circle
chart.pie
.startAngle(function(d) { return d.startAngle/2 -Math.PI/2 })
.endAngle(function(d) { return d.endAngle/2 -Math.PI/2 });
// MAKES LABELS OUTSIDE OF DONUT
//chart.pie.donutLabelsOutside(true).donut(true);
d3.select("#test2")
.datum(testdata)
.transition().duration(1200)
.attr('width', width)
.attr('height', height)
.call(chart);
// disable and enable some of the sections
var is_disabled = false;
setInterval(function() {
chart.dispatch.changeState({disabled: {2: !is_disabled, 4: !is_disabled}});
is_disabled = !is_disabled;
}, 3000);
return chart;
});
</script>
</body>
</html>