Skip to content

Commit 92e09bc

Browse files
Total Subject Time Placeholder Graph
- This was a struggle to actually get it to adjust with the size of the window. These graphs aren't perfect. But at least for now you can adjust the size of the window and the graphs will adjust as well...although with an annoying "animation"
1 parent 0f5d2f0 commit 92e09bc

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

src/graphTopics.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const topicHoursGraph_el = document.getElementById('topicHoursGraph');
2+
const ctxTopicHours = topicHoursGraph_el.getContext('2d');
3+
let topicHoursGraph; // Variable to store the chart instance
4+
5+
function getRandomNumber(min, max) {
6+
return (Math.random() * (max - min) + min).toFixed(1);
7+
}
8+
9+
function createTopicHoursGraph() {
10+
const topics = ['Topic 1', 'Topic 2', 'Topic 3', 'Topic 4', 'Topic 5'];
11+
const data = topics.map(() => getRandomNumber(10, 50));
12+
13+
return new Chart(ctxTopicHours, {
14+
type: 'doughnut',
15+
data: {
16+
labels: topics,
17+
datasets: [{
18+
data: data,
19+
backgroundColor: [
20+
'rgba(255, 99, 132, 0.5)',
21+
'rgba(54, 162, 235, 0.5)',
22+
'rgba(255, 206, 86, 0.5)',
23+
'rgba(75, 192, 192, 0.5)',
24+
'rgba(153, 102, 255, 0.5)',
25+
],
26+
borderColor: [
27+
'rgba(255, 99, 132, 1)',
28+
'rgba(54, 162, 235, 1)',
29+
'rgba(255, 206, 86, 1)',
30+
'rgba(75, 192, 192, 1)',
31+
'rgba(153, 102, 255, 1)',
32+
],
33+
borderWidth: 1
34+
}]
35+
},
36+
options: {
37+
plugins: {
38+
legend: {
39+
display: false,
40+
},
41+
},
42+
maintainAspectRatio: false,
43+
responsive: false,
44+
},
45+
});
46+
}
47+
48+
// Initial setup
49+
topicHoursGraph = createTopicHoursGraph();
50+
51+
// Resize event listener
52+
window.addEventListener('resize', () => {
53+
// Destroy the existing chart instance
54+
topicHoursGraph.destroy();
55+
56+
// Recreate the chart with updated dimensions
57+
topicHoursGraph = createTopicHoursGraph();
58+
});

src/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ <h3>10.5</h3>
8787
</div>
8888
<div class="bottom-right-graphs">
8989
<div class="container">
90-
<p>Graph</p>
90+
<canvas id="topicHoursGraph" style="width: 100%; height: auto; align-self: center"></canvas>
9191
</div>
9292
<div class="container">
9393
<canvas id="annualHoursGraph"></canvas>
@@ -99,5 +99,6 @@ <h3>10.5</h3>
9999
<script src="frame.js"></script>
100100
<script src="graphMonth.js"></script>
101101
<script src="graphAnnual.js"></script>
102+
<script src="graphTopics.js"></script>
102103
</body>
103104
</html>

0 commit comments

Comments
 (0)