Below is the code used to create a Bar Chart
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<body>
<canvas id="myChart" style="width:100%;max-width:600px"></canvas>
<script>
var xValues = [2019,2020,2021,2022,2023];
var yValues = [1000,1100,900,1200,1000,800];
new Chart("myChart", {
type: "bar",
data: {
labels: xValues,
datasets: [{
backgroundColor: ["rgba(37,150,190,0.5)","rgba(255,0,0,0.5)","rgba(0,255,0,0.5)","rgba(0,0,255,0.5)","rgba(0,255,255,0.5)"],
hoverBackgroundColor: ["rgba(37,150,190,0.7)","rgba(255,0,0,0.7)","rgba(0,255,0,0.7)","rgba(0,0,255,0.7)","rgba(0,255,255,0.7)"],
borderColor : ["rgba(37,150,190,0.8)","rgba(255,0,0,0.8)","rgba(0,255,0,0.8)","rgba(0,0,255,0.8)","rgba(0,255,255,0.8)"],
hoverBorderColor : ["rgb(0,0,0)","rgb(0,0,0)","rgb(0,0,0)","rgb(0,0,0)","rgb(0,0,0)"],
borderWidth : 2,
hoverBorderWidth : 0.5,
data: yValues
}]
},
options: {
legend: {display: false},
title: {
display: true,
text: "World Wine Production 2018"
}
}
});
</script>
</body>
</html>
Check out my YouTube video for detailed explanation :
Comments