forked from ashiguruma/patternomaly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptional.html
80 lines (68 loc) · 1.91 KB
/
optional.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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Patternomaly Optional</title>
<style>
body {
font-family: Helvetica, Arial, sans-serif;
}
label[for=pattern-switch] {
background-color: #aaa;
border-radius: 4px;
color: white;
display: inline-block;
margin-bottom: 20px;
padding: 10px 10px 10px 8px;
}
</style>
<script src='Chart.js' charset='utf-8'></script>
<script src='../dist/patternomaly.js'></script>
</head>
<body onload='load();'>
<label for="pattern-switch">
<input type="checkbox" id="pattern-switch">
toggle patterns
</label>
<canvas id='donut' width='500' height='400'></canvas>
<script>
var load = function() {
var colors = [
'#1f77b4', '#e377c2', '#ff7f0e', '#2ca02c', '#bcbd22', '#d62728',
'#17becf', '#9467bd', '#7f7f7f', '#8c564b', '#3366cc'
];
var patterns = pattern.generate(colors);
var donutCanvas = document.getElementById('donut')
var donutContext = donutCanvas.getContext('2d');
var dataset = {
datasets: [{
data: [
300, 50, 100, 210, 140,
56, 80, 260, 210, 130,
283
],
backgroundColor: colors
}],
labels: [
'One', 'Two', 'Three', 'Four', 'Five',
'Six', 'Seven', 'Eight', 'Nine', 'Ten',
'Eleven'
]
};
var donut = new Chart(donutContext, {
type: 'doughnut',
data: dataset,
options: {
responsive: false
}
});
var patternSwitch = document.querySelector('#pattern-switch');
patternSwitch.addEventListener('change', function (e) {
var fill = (e.currentTarget.checked) ? patterns : colors;
donut.data.datasets[0].backgroundColor = fill;
donut.update();
});
};
</script>
</body>
</html>