Chart
プロットの基本要素で組み立てる棒グラフと折れ線グラフです。
MonTueWedThuFriSatSun
- Visits
インポート
「インポート」セクションimport { Chart, ChartBody, ChartContent, ChartPlot, ChartGrid, ChartBars, ChartLine, ChartYAxisLabels, ChartAxisLabels, ChartLegend, ChartLegendItem,} from "@pelagornis/page/components";上のプレビューはこのファイルを描画したものです。src/components/ にコピーして使い始めてください。
import { Chart, ChartAxisLabels, ChartBars, ChartBody, ChartContent, ChartGrid, ChartLegend, ChartLegendItem, ChartPlot, ChartYAxisLabels,} from "@pelagornis/page/components";
const visits = [45, 52, 38, 65, 42, 80, 55];const days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
export default function ChartDemo() { return ( <Chart className="w-full"> <ChartBody> <ChartContent> <ChartYAxisLabels values={visits} /> <ChartPlot aria-label="Weekly page visits"> <ChartGrid values={visits} /> <ChartBars values={visits} seriesColor="brand" /> </ChartPlot> <ChartAxisLabels labels={days} /> </ChartContent> </ChartBody> <ChartLegend> <ChartLegendItem seriesColor="brand">Visits</ChartLegendItem> </ChartLegend> </Chart> );}MDX で使う
「MDX で使う」セクションChart は React の状態を共有する複数のパーツで構成されます。MDX に書いた子要素はそれぞれ別のアイランドとして描画されるため、パーツ同士がつながりません。上の例のように .tsx ファイルで組み立て、そのファイルをインポートしてください。
---title: Example---
import ChartExample from "../../components/ChartExample";
<ChartExample client:load />client:load はページの読み込み時にアイランドをハイドレートします。ページの下の方にあるコンテンツには client:visible を使ってください。
Markdoc で使う
「Markdoc で使う」セクションMarkdoc のタグは Astro コンポーネントを描画しますが、このコンポーネントにはクライアントの状態が必要です。例をハイドレートする .astro ファイルで包み、そのファイルをタグとして登録してください。
---import ChartExample from "../ChartExample";---
<ChartExample client:load />import { component, defineMarkdocConfig } from "@astrojs/markdoc/config";import starlightMarkdoc from "@astrojs/starlight-markdoc";import pageMarkdoc from "@pelagornis/page/markdoc";
export default defineMarkdocConfig({ extends: [starlightMarkdoc(), pageMarkdoc()], tags: { "chart-example": { render: component("./src/components/markdoc/ChartExample.astro"), selfClosing: true, }, },});{% chart-example /%}コンポーネントを構成するパーツと、それぞれが描画する data-refineui のロールです。
| パーツ | ロール |
|---|---|
root | chart |
axis_labels | chart-axis-labels |
bar | chart-bar |
bar_track | chart-bar-track |
bars | chart-bars |
body | chart-body |
content | chart-content |
grid | chart-grid |
hit_area | chart-hit-area |
legend | chart-legend |
legend_item | chart-legend-item |
line | chart-line |
line_area | chart-line-area |
line_stroke | chart-line-stroke |
plot | chart-plot |
plot_frame | chart-plot-frame |
point | chart-point |
tooltip | chart-tooltip |
y_axis | chart-y-axis |
- デザインのガイドとトークンの詳細は RefineUI · Chart を参照してください。
- 共通のルールは MDX で使う と Markdoc で使う を参照してください。