LineChart
Chart.js用の高度にカスタマイズ可能な折れ線グラフラッパー。
基本的な使い方
デフォルトでは、`LineChart` コンポーネントは週間トラフィックを示すプレースホルダーデータセットをレンダリングします。
Weekly Traffic
astro
---
import LineChart from '@/components/data-display/LineChart.astro';
---
<LineChart title="Weekly Traffic" class="w-full h-64" /> カスタムデータ
カスタムの `data` と `options` を渡して、複数のデータセットやカスタムスケールを含め、折れ線グラフを完全にカスタマイズできます。
Traffic Acquisition
astro
---
import type { ChartData, ChartOptions } from 'chart.js';
const trafficData: ChartData<'line'> = {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
datasets: [
{
label: 'Organic Search',
data: [1500, 2000, 1800, 2500, 2200, 3000],
borderColor: '#f97316',
backgroundColor: 'rgba(249, 115, 22, 0.1)',
borderWidth: 2,
tension: 0.4,
fill: true,
pointRadius: 3,
pointHoverRadius: 5,
},
{
label: 'Direct',
data: [1000, 1200, 1100, 1400, 1300, 1600],
borderColor: '#18181b',
backgroundColor: 'transparent',
borderWidth: 2,
borderDash: [5, 5],
tension: 0.4,
fill: false,
pointRadius: 0,
pointHoverRadius: 5,
}
]
};
const trafficOptions: ChartOptions<'line'> = {
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 } }
}
};
---
<LineChart title="Traffic Acquisition" data={trafficData} options={trafficOptions} class="w-full h-72" /> APIリファレンス
| プロパティ | 説明 | タイプ | デフォルト |
|---|---|---|---|
| class | グラフコンテナに適用する追加のCSSクラス。 | string | - |
| title | 上部に表示されるグラフのタイトル。 | string | - |
| tension | 線のベジェ曲線の張力。直線を描画するには 0 に設定します。 | number | 0.4 |
| data | 有効な Chart.js データオブジェクト。 | ChartData<'line'> | - |
| options | 有効な Chart.js オプションオブジェクト。 | ChartOptions<'line'> | - |