-
Notifications
You must be signed in to change notification settings - Fork 0
/
welcomeAccount1.html
84 lines (76 loc) · 2.33 KB
/
welcomeAccount1.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to Your Account</title>
<!-- Bootstrap CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h2 class="text-center mt-4">Welcome to Your Account</h2>
<div class="row">
<div class="col-md-6 offset-md-3">
<canvas id="myPieChart"></canvas>
</div>
</div>
</div>
<div>
<p class="text-center"><a href="homepage.html">Already have an account? Log in</a></p>
</div>
<!-- Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$.ajax({
url: 'http://localhost:5050/pie_chart',
type: 'POST',
dataType: 'json',
success: function(data) {
renderPieChart(data.categorical_data_percentage);
},
error: function(xhr, status, error) {
console.error(error);
alert('Failed to fetch data from the API.');
}
});
});
function renderPieChart(data) {
var labels = Object.keys(data);
var values = Object.values(data);
var pieChartData = {
labels: labels,
datasets: [{
data: values,
backgroundColor: generateRandomColors(values.length),
borderWidth: 1
}]
};
var options = {
responsive: true,
maintainAspectRatio: false
};
var ctx = document.getElementById('myPieChart').getContext('2d');
var myPieChart = new Chart(ctx, {
type: 'pie',
data: pieChartData,
options: options
});
}
function generateRandomColors(count) {
var colors = [];
var letters = '0123456789ABCDEF';
for (var i = 0; i < count; i++) {
var color = '#';
for (var j = 0; j < 6; j++) {
color += letters[Math.floor(Math.random() * 16)];
}
colors.push(color);
}
return colors;
}
</script>
</body>
</html>