Chart.js
Bar Chart
Vertical bar chart with custom colors and rounded corners.
By EZ4Code Team
chartbar
Code
const ctx = document.getElementById('barChart').getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
datasets: [{
label: 'Revenue (k$)',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: 'rgba(54, 162, 235, 0.6)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1,
borderRadius: 4,
barPercentage: 0.8
}]
},
options: {
responsive: true,
scales: { y: { beginAtZero: true } }
}
});Explanation
Creates a vertical bar chart from a canvas context; each dataset supplies an array of values paired with the labels array. backgroundColor and borderColor can be single colors or per-bar arrays, and borderRadius softens the corners. Set y.beginAtZero to avoid misleading axes on positive data.
More Chart.js Snippets
Line Chart
Smooth line chart with fill, tension, and hover styling.
Pie Chart
Pie chart with per-slice colors and legend positioning.
Doughnut Chart
Doughnut chart with cutout control and centered title.
Radar Chart
Multi-series radar chart for comparing entities across dimensions.
Responsive Chart
Chart that fills its container with maintainAspectRatio disabled.
Options Configuration
Title, legend, axis formatting, animations, and live updates.