ColumnChart
A vertical bar chart component representing categorical data.
Basic Usage
By default, the `ColumnChart` renders vertical bars showing monthly revenue.
Monthly Revenue
astro
---
import ColumnChart from '@/components/data-display/ColumnChart.astro';
---
<ColumnChart title="Monthly Revenue" class="w-full h-64" /> Custom Data
Pass custom `data` and `options` to configure multi-dataset column charts.
Quarterly Sales by Category
astro
---
import type { ChartData, ChartOptions } from 'chart.js';
const salesData: ChartData<'bar'> = {
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
datasets: [
{
label: 'Hardware',
data: [45000, 52000, 48000, 61000],
backgroundColor: '#f97316',
borderRadius: 4,
barPercentage: 0.6,
},
{
label: 'Software',
data: [32000, 39000, 41000, 55000],
backgroundColor: '#94a3b8',
borderRadius: 4,
barPercentage: 0.6,
}
]
};
const salesOptions: ChartOptions<'bar'> = {
plugins: {
legend: {
display: true,
position: 'top',
labels: { usePointStyle: true, padding: 20 }
}
},
scales: {
x: { grid: { display: false }, border: { display: false } },
y: { grid: { color: '#e4e4e7', tickBorderDash: [5, 5] }, border: { display: false } }
}
};
---
<ColumnChart title="Quarterly Sales by Category" data={salesData} options={salesOptions} class="w-full h-72" /> API Reference
| Property | Description | Type | Default |
|---|---|---|---|
| class | Additional CSS classes to apply to the chart container. | string | - |
| title | The title of the chart displayed at the top. | string | - |
| borderRadius | The border radius of the bars. | number | 4 |
| data | A valid Chart.js data object. | ChartData<'bar'> | - |
| options | A valid Chart.js options object. | ChartOptions<'bar'> | - |