DoughnutChart
A highly customizable doughnut chart wrapper for Chart.js.
Basic Usage
By default, the `DoughnutChart` component renders a placeholder dataset showing device usage.
Device Usage
astro
---
import DoughnutChart from '@/components/data-display/DoughnutChart.astro';
---
<DoughnutChart title="Device Usage" class="w-64 h-64" /> Custom Data
You can pass custom `data` and `options` to fully customize the doughnut chart.
Demographics
astro
---
import type { ChartData, ChartOptions } from 'chart.js';
const demographicsData: ChartData<'doughnut'> = {
labels: ['18-24', '25-34', '35-44', '45+'],
datasets: [
{
data: [25, 40, 20, 15],
backgroundColor: ['#10b981', '#14b8a6', '#06b6d4', '#0ea5e9'],
borderWidth: 0,
hoverOffset: 4,
}
]
};
const demographicsOptions: ChartOptions<'doughnut'> = {
cutout: '60%',
plugins: {
legend: {
position: 'right',
labels: { usePointStyle: true, padding: 20 }
}
}
};
---
<DoughnutChart title="Demographics" data={demographicsData} options={demographicsOptions} class="w-80 h-80" /> 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 | - |
| cutout | The percentage of the chart that is cut out of the middle. | string | '70%' |
| data | A valid Chart.js data object. | ChartData<'doughnut'> | - |
| options | A valid Chart.js options object. | ChartOptions<'doughnut'> | - |