Chart
時系列の数値を、棒グラフか折れ線グラフで示す。通常はグレーの棒で、選択した 1 本だけをプライマリカラーにする。値は文字と表でも表示する。
tsx
import { Chart, Sparkline } from "knowidea-ui";カテゴリ: Charts。
Demos
デモの数値はすべてサンプルであり、実際の値ではない。
Bars
クリックまたは矢印キーで選択すると、値と内訳が表示される。基準線には直接ラベルを付ける。値のない点は「記録なし」と表示する。
10 月 13 日35,701件
10 月 13 日の内訳
- A17,851
- B10,710
- C7,140
Show code
tsx
import { Chart, type ChartPoint } from "knowidea-ui";const days = Array.from({ length: 30 }, (_, i) => { const d = new Date(2026, 8, 14 + i); const v = i === 16 ? null : 18000 + ((i * 7919) % 9000) + i * 450; return { key: `d${i}`, label: `${d.getMonth() + 1}/${d.getDate()}`, detail: `${d.getMonth() + 1} 月 ${d.getDate()} 日`, value: v, breakdown: v == null ? undefined : [{ label: "A", value: Math.round(v * 0.5) }, { label: "B", value: Math.round(v * 0.3) }, { label: "C", value: Math.round(v * 0.2) }], } satisfies ChartPoint;});function Bars() { return <div style={{ width: "100%" }}><Chart data={days} unit="件" ariaLabel="日ごとの件数(棒)" reference={{ value: 25000, label: "目標 25,000" }} /></div>;}Line
値のない点があると、線が途切れる。
10 月 13 日35,701件
10 月 13 日の内訳
- A17,851
- B10,710
- C7,140
Show code
tsx
import { Chart, type ChartPoint } from "knowidea-ui";const days = Array.from({ length: 30 }, (_, i) => { const d = new Date(2026, 8, 14 + i); const v = i === 16 ? null : 18000 + ((i * 7919) % 9000) + i * 450; return { key: `d${i}`, label: `${d.getMonth() + 1}/${d.getDate()}`, detail: `${d.getMonth() + 1} 月 ${d.getDate()} 日`, value: v, breakdown: v == null ? undefined : [{ label: "A", value: Math.round(v * 0.5) }, { label: "B", value: Math.round(v * 0.3) }, { label: "C", value: Math.round(v * 0.2) }], } satisfies ChartPoint;});function Line() { return <div style={{ width: "100%" }}><Chart type="line" data={days.slice(-14)} unit="件" ariaLabel="日ごとの件数(線)" breakdownTitle="内訳" /></div>;}Sparkline
線と最後の点だけを描く。値は隣の数字が伝える。Stat の中でも使われる。
Show code
tsx
import { Sparkline } from "knowidea-ui";function Tiny() { return <Sparkline data={[3, 5, 4, 8, 7, 11, 12]} label="直近 7 日の推移" />;}States
ローディングと空の表示を切り替えて確認できる。
10 月 13 日35,701
10 月 13 日の内訳
- A17,851
- B10,710
- C7,140
Show code
tsx
import { useState } from "react";import { Chart, Button, type ChartPoint } from "knowidea-ui";const days = Array.from({ length: 30 }, (_, i) => { const d = new Date(2026, 8, 14 + i); const v = i === 16 ? null : 18000 + ((i * 7919) % 9000) + i * 450; return { key: `d${i}`, label: `${d.getMonth() + 1}/${d.getDate()}`, detail: `${d.getMonth() + 1} 月 ${d.getDate()} 日`, value: v, breakdown: v == null ? undefined : [{ label: "A", value: Math.round(v * 0.5) }, { label: "B", value: Math.round(v * 0.3) }, { label: "C", value: Math.round(v * 0.2) }], } satisfies ChartPoint;});function Toggle() { const [kind, setKind] = useState<"ready" | "loading" | "empty">("ready"); return ( <div style={{ width: "100%", display: "grid", gap: "var(--space-3)" }}> <div style={{ display: "flex", gap: "var(--space-2)", flexWrap: "wrap" }}> {(["ready", "loading", "empty"] as const).map((k) => <Button key={k} variant={kind === k ? "primary" : "secondary"} onClick={() => setKind(k)}>{k}</Button>)} </div> <Chart data={days.slice(-7)} state={kind} ariaLabel="状態の切り替え" /> </div> );}States
すべてのコンポーネントが、Empty、Loading、Error、Disabled、Focus の 5 つの状態を備える。Hover と Active は、確認用に固定して表示している。そのコンポーネントにあてはまらない状態は「対象外」とし、理由を添える。
| State | Appearance |
|---|---|
| Empty | 記録なし |
| Loading | 読み込み中 |
| Error | 対象外。データを取得できなかったときは、グラフを描かず、近くの Alert で理由を示す |
| Disabled | 対象外。グラフは無効状態を持たない。値のない点は「記録なし」と表示する(上のデモの 9/30) |
| Focus | 10 月 13 日35,701 10 月 13 日の内訳
棒に Tab で移り、矢印キーで選択を移動する。Home と End で先頭と末尾に移動する |
API
| Name | Type | Default | Description |
|---|---|---|---|
data | ChartPoint[] | - | { key, label, detail?, value: number | null, breakdown? }。null は値のない点 |
type | "bar" | "line" | "bar" | 棒グラフか折れ線グラフか |
ariaLabel | string | - | グラフの名前(スクリーンリーダー向け)。必須 |
unit | string | - | 単位 |
height | number | 200 | 軸の高さ(px) |
reference | { value, label } | - | 基準線。直接ラベルを付ける |
selectedKey / defaultSelectedKey / onSelect | string / string / (key) => void | - | 選択中の点(制御と非制御) |
state | "ready" | "loading" | "empty" | "ready" | 状態 |
emptyText / loadingText / breakdownTitle | string | "記録なし" / "読み込み中" / "内訳" | 表示する文言 |
prevLabel / nextLabel | string | "前の点" / "次の点" | 前後の点に移動するボタンの名前 |
CSS
Classes and data attributes
| Name | Description |
|---|---|
.ki-chart | 本体。data-state: loading | empty |
.ki-chart__readout、__plot、__svg、__col、__bar、__dot、__line、__ref、__break | 内部の要素。__col[data-selected] が選択中の点 |
CSS variables
コンポーネントが参照するのは、役割を表す名前の変数だけで、素の値は参照しない。オーバーライドの方法は Overriding を参照。
| Variable | Usage |
|---|---|
| --color-line-strong、--color-primary、--color-primary-hover | 棒、選択中の棒、選択中かつホバー時の棒 |
| --color-line、--color-text-muted | 目盛りの線と文字 |
| --color-warn | 基準線 |
| --font-mono | 数値と目盛りのフォント |
Accessibility
- 各点が role="button"、aria-pressed、aria-label(日付と値)を持つ。矢印キー、Home、End で移動する
- 選択した点の値は aria-live で読み上げ、内訳は表のように文字で表示する。色だけに頼らない
- 棒 1 本の幅が 44px に満たないため、タップ領域は前後のボタン(44px)で補う