콘텐츠로 이동
Page

Chart

플롯 기본 요소로 조합하는 막대·선 차트입니다.

MonTueWedThuFriSatSun
  • Visits
import {
Chart,
ChartBody,
ChartContent,
ChartPlot,
ChartGrid,
ChartBars,
ChartLine,
ChartYAxisLabels,
ChartAxisLabels,
ChartLegend,
ChartLegendItem,
} from "@pelagornis/page/components";

위 미리보기는 이 파일을 렌더링한 것입니다. src/components/에 복사해서 시작하세요.

src/components/ChartExample.tsx
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>
);
}

Chart 컴포넌트는 React 상태를 공유하는 여러 부분으로 이루어집니다. MDX에 적은 자식은 각각 별도의 아일랜드로 렌더링되어 부분끼리 서로 닿지 않습니다. 위 예제처럼 .tsx 파일에서 조합한 뒤 그 파일을 가져오세요.

src/content/docs/example.mdx
---
title: Example
---
import ChartExample from "../../components/ChartExample";
<ChartExample client:load />

client:load는 페이지를 불러올 때 아일랜드를 하이드레이션합니다. 페이지 아래쪽에 있는 콘텐츠에는 client:visible을 쓰세요.

Markdoc 태그는 Astro 컴포넌트를 렌더링하는데, 이 컴포넌트는 클라이언트 상태가 필요합니다. 예제를 하이드레이션하는 .astro 파일로 감싼 뒤, 그 파일을 태그로 등록하세요.

src/components/markdoc/ChartExample.astro
---
import ChartExample from "../ChartExample";
---
<ChartExample client:load />
markdoc.config.mjs
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,
},
},
});
src/content/docs/example.mdoc
{% chart-example /%}

컴포넌트를 이루는 부분과 각 부분이 렌더링하는 data-refineui 역할입니다.

부분역할
rootchart
axis_labelschart-axis-labels
barchart-bar
bar_trackchart-bar-track
barschart-bars
bodychart-body
contentchart-content
gridchart-grid
hit_areachart-hit-area
legendchart-legend
legend_itemchart-legend-item
linechart-line
line_areachart-line-area
line_strokechart-line-stroke
plotchart-plot
plot_framechart-plot-frame
pointchart-point
tooltipchart-tooltip
y_axischart-y-axis