INTEGRATIONS / ANALYTICS
Keep the numbers readable.
Charts with an exact data view, inside a reporting workflow your application can own.
Start with the workflow.
The analytics dashboard combines reporting periods, three derived metrics, line/bar/area views, series controls and CSV export. Loading, empty and rejected reports use the same layout. Its default records are deterministic examples.
npx shadcn@latest add https://ui.bld8.dev/r/analytics-dashboard.jsonNext.js and React/Vite starters contain the same editable React source. The example supplies no analytics collector, accounts, database or hosted reporting service.
Connect a report.
'use client';
import {AnalyticsDashboard, type AnalyticsDashboardProps}
from '@bld8/blocks';
const loadReport: NonNullable<AnalyticsDashboardProps['loadReport']> =
async (period, {signal}) => {
const response = await fetch(
'/api/reports?period=' + encodeURIComponent(period), {signal}
);
if (!response.ok) throw new Error('Report unavailable.');
return response.json();
};
<AnalyticsDashboard loadReport={loadReport} />Return a matching period (week, month or quarter) and records containing id, label, completed and failed. Counts must be nonnegative safe integers, with stable unique IDs and labels. The block validates the response before displaying or exporting it. Keep the loader reference stable, forward its AbortSignal and authorise report access on your server.
Period changes and retries have their own request identity. Replaced or cancelled requests cannot overwrite a newer report, and asynchronous results do not move focus. Your API owns date boundaries, timezones, aggregation and permissions; labels are supplied display text.
Use the chart separately.
<Chart label="Weekly requests" data={data}
series={[
{id:"completed",label:"Completed",tone:"primary"},
{id:"failed",label:"Failed",tone:"accent"}
]} type="line" />Chart accepts labelled categories and named numeric series. Each category has a values object containing a finite number or null for every series. Null means missing data; a line does not connect across it. Signed values retain a zero baseline. Use the same unit for series sharing the axis, and use valueFormatter to format values without changing them.
In Next.js, Chart and AnalyticsDashboard are client components. Pass serialisable data from a Server Component, and define loader or formatting functions inside a client boundary. The separate chart-state and analytics-state modules contain pure validation and calculation helpers.
Explore points with the arrow keys, Home and End, or use the pointer. The detail readout keeps the values in a steady place. Legends control the visible series; Show data exposes every original value in a table. Patterns and text accompany colour. Reduced motion removes animated travel.
Keep the boundary clear.
This chart renders at most 366 categories and six series. It is a bounded comparison view, with evenly spaced supplied categories. It does not parse dates, interpolate missing values, stream data or downsample a larger dataset. Filter or aggregate on the service when needed.
Total requests, completion rate and peak-day counts are calculated from the loaded report. An empty report has no peak or completion rate; missing values are not silently treated as measurements. CSV uses the same report with quoted fields and spreadsheet-formula protection. Revalidate exported content for your destination.
Check your own real labels, keyboard flow and assistive-technology behaviour. Automated browser checks complement that review.