Create a html page and script.js
Insert the following scripts into the header. I have included
Bulma as well in the html template below to help with formatting.
chart.js
Jquery for the fetch functions
<!DOCTYPE html>
<html>
<head>
<title>Graph Js Template</title>
<!-- Bulma CSS -->
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bulma@1.0.0/css/bulma.min.css">
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<style>
.chart{
width:400px;
}
</style>
<body>
<!-- Your content goes here -->
<div class="container">
<h1 class="title">Title</h1>
<div class="chart">
<canvas id="chartArea"></canvas>
</div>
</div>
<!-- Bulma JS -->
<script
src="https://cdn.jsdelivr.net/npm/bulma@0.9.3/js/bulma.min.js"></script>
<script src="script.js"></script>
</body>
</html>
3. Now in your javascript file you can insert the following template and you should see a graph appear with static figures
const chartArea = document.getElementById('chartArea');
var chartExample; //global
chartExample = new Chart(chartArea, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});