Quill
Custom Charting Library

React SDK

Custom Charting Library

A report drawn with shadcn, TanStack Charts, Tremor, MUI X Charts, Recharts, Highcharts, Chart.js, D3, AG Charts or Nivo.

The stack you choose picks the code on this page. Options marked coming soon can't be chosen yet.

Copies the Quill CLI's install command: curl -fsSL https://quill.co/install.sh | shView as MarkdownThe whole page, with the code for the chosen stack.
import { useReport } from "@quillsql/react";

// Shared by every example below.
export function useChart(reportId: string) {
  const { chart, chartLoading, chartType } = useReport(reportId);
  const x = chart?.xAxisField;
  const ys = chart?.yAxisFields.map((y) => y.field) ?? [];
  const rows = (chart?.rows ?? []).map((row) => ({ ...row, ...Object.fromEntries(ys.map((y) => [y, Number(row[y])])) }));
  return { rows, x, ys, chartType, loading: chartLoading };
}
import { Area, AreaChart, Bar, BarChart, CartesianGrid, Line, LineChart, Pie, PieChart, XAxis, YAxis } from "recharts";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent } from "@/components/ui/chart";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";

// Quill chartType → Recharts chart, series and options.
const CHART_TYPES = {
  column: { Chart: BarChart, Series: Bar },
  bar: { Chart: BarChart, Series: Bar, horizontal: true },
  stacked: { Chart: BarChart, Series: Bar, stacked: true },
  "stacked bar": { Chart: BarChart, Series: Bar, horizontal: true, stacked: true },
  line: { Chart: LineChart, Series: Line },
  area: { Chart: AreaChart, Series: Area },
};

export function ShadcnReport({ reportId, name }: { reportId: string; name: string }) {
  const { rows, x, ys, chartType, loading } = useChart(reportId);
  // Each series is a --color-<field> variable, set by ChartContainer.
  const config = Object.fromEntries(ys.map((y, i) => [y, { label: y, color: `var(--chart-${(i % 5) + 1})` }]));

  switch (loading ? "loading" : chartType) {
    case "loading":
      return <Card><CardHeader><CardDescription>{name}</CardDescription><CardTitle>Loading…</CardTitle></CardHeader></Card>;
    case "metric":
      return (
        <Card>
          <CardHeader>
            <CardDescription>{name}</CardDescription>
            <CardTitle className="text-2xl font-semibold tabular-nums">{rows[0]?.[ys[0]]?.toLocaleString()}</CardTitle>
          </CardHeader>
        </Card>
      );
    case "table":
      return (
        <Card>
          <CardHeader><CardTitle>{name}</CardTitle></CardHeader>
          <CardContent>
            <Table>
              <TableHeader><TableRow>{[x, ...ys].map((f, j) => <TableHead key={j}>{f}</TableHead>)}</TableRow></TableHeader>
              <TableBody>
                {rows.map((row, i) => <TableRow key={i}>{[x, ...ys].map((f, j) => <TableCell key={j}>{row[f]?.toLocaleString()}</TableCell>)}</TableRow>)}
              </TableBody>
            </Table>
          </CardContent>
        </Card>
      );
    case "pie":
      return (
        <Card>
          <CardHeader><CardTitle>{name}</CardTitle></CardHeader>
          <CardContent>
            <ChartContainer config={config} className="mx-auto aspect-square max-h-[250px]">
              <PieChart>
                <ChartTooltip content={<ChartTooltipContent hideLabel />} />
                <Pie data={rows.map((r, i) => ({ ...r, fill: `var(--chart-${(i % 5) + 1})` }))} dataKey={ys[0]} nameKey={x} />
              </PieChart>
            </ChartContainer>
          </CardContent>
        </Card>
      );
    default: {
      const type = CHART_TYPES[chartType];
      if (!type) return null;
      const { Chart, Series, horizontal, stacked } = type;
      return (
        <Card>
          <CardHeader><CardTitle>{name}</CardTitle></CardHeader>
          <CardContent>
            <ChartContainer config={config}>
              <Chart accessibilityLayer data={rows} layout={horizontal ? "vertical" : "horizontal"}>
                <CartesianGrid vertical={!!horizontal} horizontal={!horizontal} />
                {horizontal
                  ? <><YAxis dataKey={x} type="category" tickLine={false} axisLine={false} width={90} /><XAxis type="number" hide /></>
                  : <XAxis dataKey={x} tickLine={false} axisLine={false} tickMargin={10} />}
                <ChartTooltip cursor={false} content={<ChartTooltipContent />} />
                {ys.length > 1 && <ChartLegend content={<ChartLegendContent />} />}
                {ys.map((y) => (
                  <Series key={y} dataKey={y} stackId={stacked ? "a" : undefined} fill={`var(--color-${y})`} stroke={`var(--color-${y})`}
                    {...(Series === Bar ? { radius: stacked ? 0 : 8 } : { type: "natural", strokeWidth: 2, dot: false, fillOpacity: 0.4 })} />
                ))}
              </Chart>
            </ChartContainer>
          </CardContent>
        </Card>
      );
    }
  }
}