Connecting Real Data
Wiring any chart to a real source: fetch in an effect, SWR or React Query, server components, and streaming — with every outcome mapped onto a status.
fetch in an effect — all four outcomes
@spectrumui/chart-data
SOLfrom /api/candles
$0.00000.00%
Loading chart data
Login to view codeCreate a free account to access component source code
Login to view codeCreate a free account to access component source code
Login to view codeCreate a free account to access component source code
Login to view codeCreate a free account to access component source code
SWR / React Query — one status expression
SOLvia useSWR
$0.00000.00%
Loading chart data
Login to view codeCreate a free account to access component source code
Login to view codeCreate a free account to access component source code
Login to view codeCreate a free account to access component source code
Login to view codeCreate a free account to access component source code
Streaming — seed, append, bound the window
SOLstreaming
$245.85+3.44%
Login to view codeCreate a free account to access component source code
Login to view codeCreate a free account to access component source code
Login to view codeCreate a free account to access component source code
Login to view codeCreate a free account to access component source code
Manual installation
Prefer to copy by hand? Open the Code tab on any example above and switch to the file you need — every source file is there, not just the demo. Drop them in your project like this:
chart-engine.tsxcomponents/spectrumui/charts/chart-engine.tsxmarket-chart.tsxcomponents/spectrumui/charts/market-chart.tsxchart-data.tsxcomponents/spectrumui/charts/chart-data.tsx
There is nothing to install — this chart draws its own SVG and imports only @/lib/utils.
Usage
import { useChartData } from '@/components/spectrumui/charts/chart-data';
const { data, status, retry } = useChartData<Point[]>('/api/metrics');- Every chart takes the same
statusunion, so one fetch hook drives all of them. retryis wired to the error state's button — pass it straight through asonRetry.