LazyChart
Shared ComponentsDefer mounting chart content until it approaches the viewport.
Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.
"use client";
import { LazyChart } from "@dashboardpack/core/components/shared/lazy-chart";
import { Progress } from "@dashboardpack/core/components/ui/progress";
export default function LazyChartExample() {
return (
<div className="w-full max-w-sm">
<LazyChart height={180}>
<div className="space-y-5 rounded-xl border bg-background p-6">
<h3 className="font-medium">Quarterly targets</h3>
{[
{ name: "Revenue", value: 75 },
{ name: "Growth", value: 60 },
{ name: "Retention", value: 92 },
].map((metric) => (
<div key={metric.name} className="space-y-2">
<div className="flex justify-between text-xs">
<span>{metric.name}</span>
<span>{metric.value}%</span>
</div>
<Progress
value={metric.value}
role="progressbar"
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={metric.value}
aria-label={metric.name}
/>
</div>
))}
</div>
</LazyChart>
</div>
);
}Usage
Wrap chart content in LazyChart to postpone mounting until it approaches the viewport. Match height to the eventual chart to limit layout movement. This defers rendering; use dynamic import separately to defer downloading chart code.
import { LazyChart } from "@dashboardpack/core/components/shared/lazy-chart";Available in the included @dashboardpack/core package. Copy the complete example from Source code for all imports and state. Add "use client" when using hooks or event handlers. See installation and theming for project setup.
API reference
Common props and defaults. Slot-specific props are named below; native elements also accept their standard HTML attributes. The component TypeScript definitions are the complete type reference.
| Prop | Type / Default | Description |
|---|---|---|
| children | ReactNodeDefault: required | Chart or expensive visual content. |
| height | numberDefault: 320 | Skeleton height in pixels before mounting. |
| className | stringDefault: — | Extend the observer container styles. |