Skip to content
silverpoint
Documentation menu

Concepts

Export & imperative handle

Each chart exposes a handle with toSVGString() and getGeometry(). The exported SVG carries its own ground colours, so it renders the same outside the app.

Try it

Monthly budgetMonthly budget
Monthly budget
namevalueshare
Rent3838%
Food2222%
Savings1515%
Transport1414%
Leisure1111%

In your code

tsx
import { useRef } from 'react';
import { LineChart, type ChartHandle } from '@silverpoint/react/line-chart';

export function Exportable({ data }: { data: { hour: string; hits: number }[] }) {
  const chart = useRef<ChartHandle>(null);
  const download = () => {
    const svg = chart.current?.toSVGString() ?? '';
    window.open(URL.createObjectURL(new Blob([svg], { type: 'image/svg+xml' })));
  };
  return (
    <>
      <LineChart ref={chart} data={data} xKey="hour" valueKey="hits" title="Hits per hour" />
      <button onClick={download}>Export SVG</button>
    </>
  );
}