Trading dashboard for React
Candlesticks, a flashing order book, a buy/sell ticket and a portfolio donut. Free.
Candlesticks, a flashing order book, a buy/sell ticket and a portfolio donut. Free.
"use client";
import { LedgerDashboard } from "@/components/ledger/LedgerDashboard";
export default function Page() {
return <LedgerDashboard />;
}"use client";
import {
Bar,
BarChart,
CartesianGrid,
DefaultZIndexes,
ErrorBar,
Rectangle,
XAxis,
YAxis,
type BarShapeProps,
} from "recharts";
import { ChartContainer, ChartTooltip, type ChartConfig } from "@/components/ui/chart";
export type Candle = { time: string; open: number; high: number; low: number; close: number };
const chartConfig = {
up: { label: "Up", color: "var(--chart-2)" },
down: { label: "Down", color: "var(--chart-1)" },
} satisfies ChartConfig;
// The body spans open to close. The wick is the distance from the top of the body down to low and up to high.
const body = (c: Candle): [number, number] => [Math.min(c.open, c.close), Math.max(c.open, c.close)];
const wick = (c: Candle): [number, number] => {
const top = Math.max(c.open, c.close);
return [top - c.low, c.high - top];
};
function CandleBody(props: BarShapeProps) {
const c = props.payload as Candle;
const color = c.close >= c.open ? "var(--color-up)" : "var(--color-down)";
return <Rectangle {...props} fill={color} stroke="none" />;
}
export function CandlestickChart({ data }: { data: Candle[] }) {
const low = Math.min(...data.map((c) => c.low));
const high = Math.max(...data.map((c) => c.high));
const pad = (high - low) * 0.05;
return (
<ChartContainer config={chartConfig} className="aspect-auto h-72 w-full">
<BarChart data={data}>
<CartesianGrid vertical={false} />
<XAxis dataKey="time" tickLine={false} axisLine={false} />
<YAxis domain={[low - pad, high + pad]} tickLine={false} axisLine={false} width={48} />
<ChartTooltip
cursor={false}
content={({ active, payload }) => {
const c = payload?.[0]?.payload as Candle | undefined;
if (!active || !c) return null;
return (
<div className="rounded-md border bg-background px-2.5 py-1.5 text-xs tabular-nums shadow-sm">
<div className="font-medium">{c.time}</div>
<div>O {c.open} H {c.high} L {c.low} C {c.close}</div>
</div>
);
}}
/>
{/* zIndex keeps the wick behind the body, as in the Recharts example */}
<Bar dataKey={body} shape={CandleBody} isAnimationActive={false}>
<ErrorBar dataKey={wick} width={0} stroke="var(--muted-foreground)" zIndex={DefaultZIndexes.bar - 1} />
</Bar>
</BarChart>
</ChartContainer>
);
}npx shadcn@latest add https://teodoravadani.github.io/qodesign-free/r/ledger-dashboard.jsonAll comparisons, with prices read on each library's own site.
From the blog: React Order Book Component with Tailwind: Depth Bars, Spread and Flashing Updates
From the blog: Animated SVG Line Chart in React Without a Chart Library (Draw-On Effect)
Yes, as a client component. Keep "use client" at the top of the file that renders it, as in the snippet above. App Router and Pages Router both work.
No, they're simulated. Feed it your market data.
No. Its docs build one from a Bar for the body and an ErrorBar for the wick, and the snippet above does the same inside a shadcn chart.
Not through a prop yet. The candles come from a simulated store, so you'd replace the data in store.ts with your own feed.
Yes. MIT licence, no email needed for the registry install.
Yes. The folder has a PROMPT.md. Paste it into Cursor, Lovable, v0 or Claude Code.