Skip to content

Commit a1da1bb

Browse files
committed
ADD: Bar Chart using ChartJs
1 parent c7c2d1a commit a1da1bb

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

Chart/BarChart/index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<link rel="stylesheet" href="style.css" />
8+
<title>Bar Chart</title>
9+
</head>
10+
<body>
11+
<div class="chart">
12+
<canvas id="bar-chart" role="img" width="500" aria-label="Bar Chart">
13+
<p>Bar Chart</p>
14+
</canvas>
15+
</div>
16+
</body>
17+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
18+
<script src="./script.js"></script>
19+
</html>

Chart/BarChart/script.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const barChart = document.getElementById("bar-chart")
2+
3+
new Chart(barChart, {
4+
type: "bar",
5+
data: {
6+
labels: ["JavaScript", "TypeScript", "CSS", "Python", "C", "Java"],
7+
datasets: [
8+
{
9+
label: "Like Rating",
10+
data: [7, 8, 10, 7, 5, 2],
11+
borderWidth: 1,
12+
},
13+
],
14+
},
15+
options: {
16+
scale: {
17+
y: {
18+
min: 1,
19+
max: 10,
20+
},
21+
},
22+
plugins: {
23+
legend: {
24+
display: false,
25+
},
26+
title: {
27+
display: true,
28+
text: "How much do I like these languages?",
29+
align: "center",
30+
},
31+
},
32+
},
33+
})

Chart/BarChart/style.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
html,
2+
body {
3+
height: 100%;
4+
}
5+
6+
body {
7+
display: flex;
8+
justify-content: center;
9+
align-items: center;
10+
}

0 commit comments

Comments
 (0)