To add a custom background style, you must modify the internal registry files. Follow these three steps:
- Update the Type: Add your new variant name to the
BackgroundVariant union type in src/registry/ui/background.tsx. - Create the Pattern Component: Define a React component that returns an SVG
<pattern> element containing your desired shapes. - Register the Pattern: Add your new component to the
PATTERN_MAP object in src/registry/ui/background.tsx.
Once registered, use the new variant name in the backgroundVariant prop of your chart component.
// 1. Update BackgroundVariant type
export type BackgroundVariant =
| "dots"
| "grid"
| "custom-pattern";
// 2. Create the pattern component
const CustomPattern = ({ id }: { id: string }) => (
<pattern
id={id}
x="0"
y="0"
width="24"
height="24"
patternUnits="userSpaceOnUse"
>
<path
className="text-border dark:text-border"
d="M12 2l2.2 4.6L19 9l-4.8 2.4L12 16l-2.2-4.6L5 9l4.8-2.4L12 2z"
fill="currentColor"
fillOpacity="0.35"
/>
</pattern>
);
// 3. Register in PATTERN_MAP
const PATTERN_MAP: Record<BackgroundVariant, React.FC<{ id: string }>> = {
dots: DotsPattern,
grid: GridPattern,
"custom-pattern": CustomPattern,
};
// Usage
<EvilLineChart
xDataKey="month"
data={data}
chartConfig={chartConfig}
backgroundVariant="custom-pattern"
/>