Skip to content

useScreenshot

Capture and download a chart screenshot.

const { screenshotUrl, capture, download, clear } = useScreenshot();
Field/MethodTypeDescription
screenshotUrlstring | nullJPEG data URL of the last screenshot
capture()() => voidCapture the current chart state
download(filename?)(filename?: string) => voidDownload as a file (default "chart-screenshot.jpg")
clear()() => voidClear screenshotUrl from state

The screenshot is produced via chart.getConvertPictureUrl(true, "jpeg", bgColor). Background depends on the theme: #151517 (dark) / #ffffff (light). The stored URL is cleared automatically when the chart instance, symbol or period changes (a capture always depicts one concrete chart state).

const { screenshotUrl, capture, download, clear } = useScreenshot();
<button onClick={capture}>Capture</button>;
{screenshotUrl && (
<>
<img src={screenshotUrl} alt="chart" />
<button onClick={() => download()}>Download</button>
<button onClick={clear}>Close</button>
</>
)}