-
Notifications
You must be signed in to change notification settings - Fork 11
/
pieChart.html
136 lines (90 loc) · 2.54 KB
/
pieChart.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
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Pie Chart</title>
<style>
.piechart {
width: 300px;
height: 300px;
border-radius: 50%;
background-color: antiquewhite;
margin: auto;
margin-top: 11rem;
/* background: conic-gradient( red 140deg, orange 0deg 224deg, purple 0);*/
}
</style>
</head>
<body>
<div class="piechart">
</div>
<script>
window.addEventListener("load", getData);
function getData() {
var total = 0;
var data=[];
var values = [23, 45, 21, 35, 88, 54,67 , 50, 12, 47];
var len = values.length;
for (var i = 0; i < len; i++) {
total += values[i];
}
for (var i = 0; i < len; i++) {
data[i] = values[i]*total/360;
}
console.log(data);
createPieChart(values);
}
function createPieChart(values) {
var colors = ["green", "red", "orange", "blue", "pink", "yellow", "black"];
var total = 0;
var pieChart = "";
for (var i = 0; i < values.length - 1; i++) {
var total = total + values[i];
console.log(values[i])
var x = Math.floor(Math.random() * 256);
var y = 100 + Math.floor(Math.random() * 256);
var z = 50 + Math.floor(Math.random() * 256);
var color = "rgb(" + x + "," + y + "," + z + ")";
pieChart = pieChart + color + " 0deg" + " " + total + "deg, ";
}
pieChart = pieChart + "black 0";
console.log(pieChart);
document.getElementsByClassName("piechart")[0].style.background = "conic-gradient(" + pieChart + ")";
}
</script>
<!--<script>
await Excel.run(async (context) => {
let sheet = context.workbook.worksheets.getActiveWorksheet();
// Create the headers and format them to stand out.
let headers = [
["Product", "Quantity", "Unit Price", "Totals"]
];
let headerRange = sheet.getRange("B2:E2");
headerRange.values = headers;
headerRange.format.fill.color = "#4472C4";
headerRange.format.font.color = "white";
// Create the product data rows.
let productData = [
["Almonds", 6, 7.5],
["Coffee", 20, 34.5],
["Chocolate", 10, 9.56],
];
let dataRange = sheet.getRange("B3:D5");
dataRange.values = productData;
// Create the formulas to total the amounts sold.
let totalFormulas = [
["=C3 * D3"],
["=C4 * D4"],
["=C5 * D5"],
["=SUM(E3:E5)"]
];
let totalRange = sheet.getRange("E3:E6");
totalRange.formulas = totalFormulas;
totalRange.format.font.bold = true;
// Display the totals as US dollar amounts.
totalRange.numberFormat = [["$0.00"]];
await context.sync();
});
</script>-->
</body>
</html>