Line Chart
Interactive line chart with multiple datasets using Chart.js
Revenue Overview
Code
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Revenue Overview</h3>
<canvas id="lineChart"></canvas>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
const ctx = document.getElementById('lineChart').getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
datasets: [{
label: 'Revenue',
data: [12000, 19000, 15000, 25000, 22000, 30000],
borderColor: 'rgb(59, 130, 246)',
backgroundColor: 'rgba(59, 130, 246, 0.1)',
tension: 0.4
}]
},
options: {
responsive: true,
plugins: {
legend: { display: true }
}
}
});
</script>
Bar Chart
Vertical bar chart for comparing data across categories
Monthly Sales
Code
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Monthly Sales</h3>
<canvas id="barChart"></canvas>
</div>
<script>
const ctx = document.getElementById('barChart').getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Product A', 'Product B', 'Product C', 'Product D'],
datasets: [{
label: 'Sales',
data: [65, 59, 80, 81],
backgroundColor: [
'rgba(59, 130, 246, 0.8)',
'rgba(16, 185, 129, 0.8)',
'rgba(245, 158, 11, 0.8)',
'rgba(239, 68, 68, 0.8)'
]
}]
},
options: {
responsive: true,
plugins: {
legend: { display: false }
}
}
});
</script>
Pie Chart
Circular chart showing proportional data
Market Share
Code
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Market Share</h3>
<canvas id="pieChart"></canvas>
</div>
<script>
const ctx = document.getElementById('pieChart').getContext('2d');
new Chart(ctx, {
type: 'pie',
data: {
labels: ['Chrome', 'Firefox', 'Safari', 'Edge', 'Others'],
datasets: [{
data: [65, 15, 10, 5, 5],
backgroundColor: [
'rgba(59, 130, 246, 0.8)',
'rgba(245, 158, 11, 0.8)',
'rgba(16, 185, 129, 0.8)',
'rgba(139, 92, 246, 0.8)',
'rgba(156, 163, 175, 0.8)'
]
}]
},
options: {
responsive: true,
plugins: {
legend: { position: 'bottom' }
}
}
});
</script>
Donut Chart
Pie chart with a hollow center
Traffic Sources
Code
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Traffic Sources</h3>
<canvas id="donutChart"></canvas>
</div>
<script>
const ctx = document.getElementById('donutChart').getContext('2d');
new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['Direct', 'Organic', 'Referral', 'Social'],
datasets: [{
data: [45, 30, 15, 10],
backgroundColor: [
'rgba(59, 130, 246, 0.8)',
'rgba(16, 185, 129, 0.8)',
'rgba(245, 158, 11, 0.8)',
'rgba(139, 92, 246, 0.8)'
]
}]
},
options: {
responsive: true,
plugins: {
legend: { position: 'right' }
}
}
});
</script>
Area Chart
Filled line chart showing trends over time
User Growth
Code
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">User Growth</h3>
<canvas id="areaChart"></canvas>
</div>
<script>
const ctx = document.getElementById('areaChart').getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: ['Week 1', 'Week 2', 'Week 3', 'Week 4', 'Week 5', 'Week 6'],
datasets: [{
label: 'Active Users',
data: [1200, 1900, 1500, 2500, 2200, 3000],
borderColor: 'rgb(16, 185, 129)',
backgroundColor: 'rgba(16, 185, 129, 0.2)',
fill: true,
tension: 0.4
}]
},
options: {
responsive: true,
plugins: {
legend: { display: true }
}
}
});
</script>
Multi-line Chart
Comparing multiple datasets on one chart
Sales Comparison
Code
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Sales Comparison</h3>
<canvas id="multiLineChart"></canvas>
</div>
<script>
const ctx = document.getElementById('multiLineChart').getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
datasets: [
{
label: '2024',
data: [12, 19, 15, 25, 22, 30],
borderColor: 'rgb(59, 130, 246)',
backgroundColor: 'rgba(59, 130, 246, 0.1)',
tension: 0.4
},
{
label: '2025',
data: [15, 23, 18, 28, 25, 35],
borderColor: 'rgb(16, 185, 129)',
backgroundColor: 'rgba(16, 185, 129, 0.1)',
tension: 0.4
}
]
},
options: {
responsive: true,
plugins: {
legend: { display: true }
}
}
});
</script>
Horizontal Bar Chart
Bar chart with horizontal orientation
Top Products
Code
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Top Products</h3>
<canvas id="horizontalBarChart"></canvas>
</div>
<script>
const ctx = document.getElementById('horizontalBarChart').getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Laptop', 'Smartphone', 'Tablet', 'Headphones', 'Smartwatch'],
datasets: [{
label: 'Units Sold',
data: [450, 380, 290, 510, 340],
backgroundColor: 'rgba(59, 130, 246, 0.8)'
}]
},
options: {
indexAxis: 'y',
responsive: true,
plugins: {
legend: { display: false }
}
}
});
</script>
Radar Chart
Spider/web chart for multivariate data
Skill Assessment
Code
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Skill Assessment</h3>
<canvas id="radarChart"></canvas>
</div>
<script>
const ctx = document.getElementById('radarChart').getContext('2d');
new Chart(ctx, {
type: 'radar',
data: {
labels: ['HTML', 'CSS', 'JavaScript', 'PHP', 'Laravel', 'Vue.js'],
datasets: [{
label: 'Skills',
data: [90, 85, 80, 75, 70, 65],
borderColor: 'rgb(59, 130, 246)',
backgroundColor: 'rgba(59, 130, 246, 0.2)'
}]
},
options: {
responsive: true,
plugins: {
legend: { display: true }
}
}
});
</script>
Sparklines
Small inline charts for showing trends
Revenue
$45,231
Orders
1,293
Customers
573
Code
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="text-center">
<p class="text-sm text-gray-600 dark:text-gray-400 mb-2">Revenue</p>
<canvas id="sparkline1" height="40"></canvas>
<p class="text-2xl font-bold text-gray-900 dark:text-white mt-2">$45,231</p>
</div>
<div class="text-center">
<p class="text-sm text-gray-600 dark:text-gray-400 mb-2">Orders</p>
<canvas id="sparkline2" height="40"></canvas>
<p class="text-2xl font-bold text-gray-900 dark:text-white mt-2">1,293</p>
</div>
<div class="text-center">
<p class="text-sm text-gray-600 dark:text-gray-400 mb-2">Customers</p>
<canvas id="sparkline3" height="40"></canvas>
<p class="text-2xl font-bold text-gray-900 dark:text-white mt-2">573</p>
</div>
</div>
</div>
<script>
// Revenue sparkline
new Chart(document.getElementById('sparkline1').getContext('2d'), {
type: 'line',
data: {
labels: Array(12).fill(''),
datasets: [{
data: [20, 25, 22, 30, 28, 35, 32, 40, 38, 45, 42, 48],
borderColor: 'rgb(16, 185, 129)',
borderWidth: 2,
fill: false,
tension: 0.4
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: { legend: { display: false } },
scales: { x: { display: false }, y: { display: false } }
}
});
</script>