Layouts & replay
Multi-chart layouts with synced crosshairs and ranges, and bar replay.
"use client";
import { type LayoutKind, TradingChart } from "@reincharts/widget";
import { useState } from "react";
import { Segmented, WithToolbar } from "@/components/preview/controls";
import { createDemoFeed } from "@/lib/demo-feed";
import { useDocsChartTheme } from "@/lib/use-docs-theme";
const layouts = ["single", "2h", "2v", "3", "4"] as const;
export default function MultiChartLayout() {
const theme = useDocsChartTheme();
const [feed] = useState(() => createDemoFeed());
const [layout, setLayout] = useState<LayoutKind>("4");
return (
<WithToolbar toolbar={<Segmented label="layout" value={layout} options={layouts} onChange={setLayout} />}>
<TradingChart
datafeed={feed}
defaultSymbol="REIN"
defaultResolution="60"
// the other charts of the grid show these symbols
defaultState={{ cells: ["ACME", "GLOBX", "BTCD"] }}
layout={layout}
onLayoutChange={setLayout}
// crosshairs are always synced; syncRange also pans / zooms them together
syncRange
drawingToolbar={false}
theme={theme}
/>
</WithToolbar>
);
}Multi-chart layouts
layout shows several charts in one widget: "single", "2h" (side by side), "2v" (stacked), "3" (one big + two)
or "4" (2 × 2). Users pick it from the toolbar; control it with layout + onLayoutChange, or set it in the state.
The symbols of the other charts are state.cells.
<TradingChart datafeed={feed} layout="4" defaultState={{ cells: ["ACME", "GLOBX", "BTCD"] }} syncRange />Crosshairs are always synced between the charts of a layout; syncRange also syncs panning and zooming. Click a chart
to make it active: the toolbar, legends and drawing tools act on the active chart.
To sync charts outside a single widget, use syncId on <ChartCanvas>.
Bar replay
The replay button in the toolbar opens bar replay: pick a starting bar on the chart, then play, pause,
step and change the speed. Indicators and drawings update as bars appear. Disable it with replay={false}. For your own
replay UI, use useBarReplay.