BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/boldkit/chart-export

Chart Export

boldkit/chart-export
FreeUtility

BoldKit chart export helpers — framework-agnostic, SSR-safe CSV / PNG / SVG download and fullscreen toggle. Works with any chart engine that renders an <svg> (Recharts) or <canvas> (ECharts).

Live preview

live · rendered by the registry
Rendered by boldkit on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://boldkit.dev/r/chart-export.json

Source

registry/default/lib/chart-export.tsboldkit.dev/r/chart-export.json · first 6 KB
1/**
2 * BoldKit Chart Export — framework-agnostic chart toolbar helpers.
3 *
4 * Operates on a chart's container element, so it works regardless of the
5 * rendering engine: Recharts (SVG) and ECharts (canvas) are both handled.
6 * Consumed by the React <ChartToolbar> and the Vue <ChartToolbar>.
7 *
8 * All functions are SSR-safe: they no-op on the server.
9 */
10
11const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined'
12
13function triggerDownload(href: string, filename: string) {
14 const a = document.createElement('a')
15 a.href = href
16 a.download = filename
17 document.body.appendChild(a)
18 a.click()
19 a.remove()
20}
21
22// ──────────────────────────────────────────────────────────────────
23// CSV — from the same data array you feed the chart
24// ──────────────────────────────────────────────────────────────────
25
26/** Escape a single CSV cell per RFC 4180 (quote if it contains ,"\n). */
27function csvCell(value: unknown): string {
28 const s = value == null ? '' : String(value)
29 return /[",\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s
30}
31
32/**
33 * Serialize an array of row objects to a CSV string. Columns are the union
34 * of keys across all rows, in first-seen order. Pure — no DOM access.
35 */
36export function toCSV(rows: Array<Record<string, unknown>>): string {
37 if (!rows.length) return ''
38
39 const columns: string[] = []
40 for (const row of rows) {
41 for (const key of Object.keys(row)) {
42 if (!columns.includes(key)) columns.push(key)
43 }
44 }
45
46 const lines = [
47 columns.map(csvCell).join(','),
48 ...rows.map((row) => columns.map((col) => csvCell(row[col])).join(',')),
49 ]
50 return lines.join('\n')
51}
52
53/**
54 * Serialize an array of row objects to CSV and download it.
55 * Columns are the union of keys across all rows, in first-seen order.
56 */
57export function downloadCSV(rows: Array<Record<string, unknown>>, filename = 'chart.csv'): void {
58 if (!isBrowser || !rows.length) return
59
60 const blob = new Blob([toCSV(rows)], { type: 'text/csv;charset=utf-8;' })
61 const url = URL.createObjectURL(blob)
62 triggerDownload(url, filename)
63 URL.revokeObjectURL(url)
64}
65
66// … truncated

Files it writes

  • registry/default/lib/chart-export.ts

Facts

Registry
boldkit
Type
registry:lib
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-03
Last confirmed
yesterday

Go to the source

Docs on boldkit boldkit.dev ANIBIT14/boldkit on GitHub Raw registry item This item as JSON

More from boldkit

All 94 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Math Curvesmath-curvesboldkitUtilitiesFreeno deps
Motion Coremotion-coreboldkitUtilitiesFreeno deps
UtilsutilsboldkitUtilitiesFree2 deps
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex