<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Custom Scale in Chart.js</title>
<script src=
"https://cdn.jsdelivr.net/npm/chart.js">
</script> <!-- Including Chart.js -->
</head>
<body>
<!-- Canvas element for the chart -->
<canvas id="myPercentageChart"
width="400"
height="300">
</canvas>
<script>
// Create a bar chart with a custom
// scale in the options
const ctx = document
.getElementById('myPercentageChart')
.getContext('2d');
const myBarChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue',
'Yellow', 'Green',
'Purple', 'Orange'],
datasets: [{
label: 'Percentage of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: 'rgba(0, 123, 255, 0.5)',
borderColor: 'rgba(0, 123, 255, 1)',
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true,
max: 100,
ticks: {
// Custom tick formatting to show as percentages
callback: function (value, index, values) {
return value + '%';
}
}
}
}
}
});
</script>
</body>
</html>