Charts
fable-ui/chartsFreeBlock
Render static AI-provided chart payloads using shadcn chart conventions and Recharts.
Live preview
live · rendered by the registry
Rendered by fable-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://fable-ui.shobky.com/r/charts.jsonSource
1"use client"23import * as React from "react"4import {5 Bar,6 BarChart,7 CartesianGrid,8 Cell,9 Line,10 LineChart,11 Pie,12 PieChart,13 XAxis,14 YAxis,15} from "recharts"1617import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"18import { Badge } from "@/components/ui/badge"19import {20 Card,21 CardContent,22 CardDescription,23 CardHeader,24 CardTitle,25} from "@/components/ui/card"26import {27 ChartContainer,28 ChartLegend,29 ChartLegendContent,30 ChartTooltip,31 ChartTooltipContent,32 type ChartConfig,33} from "@/components/ui/chart"34import {35 Empty,36 EmptyDescription,37 EmptyHeader,38 EmptyTitle,39} from "@/components/ui/empty"40import { Skeleton } from "@/components/ui/skeleton"41import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"42import { cn } from "@/lib/utils"43import { chartTypes, type ChartsProps, type ChartType } from "./charts.types"4445const chartTypeLabels: Record<ChartType, string> = {46 line: "Line",47 bar: "Bar",48 pie: "Pie",49}5051const chartColors = [52 "var(--chart-1)",53 "var(--chart-2)",54 "var(--chart-3)",55 "var(--chart-4)",56 "var(--chart-5)",57]5859type ResolvedSeries = {60 key: string61 label: string62 color: string63}6465type ChartProblem = {66 title: string67 description?: string68}6970function normalizeChartTypes(types?: ChartType[]): ChartType[] {71 const uniqueTypes = new Set(72 types?.filter((type) => chartTypes.includes(type))73 )7475 return uniqueTypes.size > 0 ? Array.from(uniqueTypes) : ["line"]76}7778function isFiniteNumber(value: unknown): value is number {79 return typeof value === "number" && Number.isFinite(value)80}8182function toFiniteNumber(value: unknown) {83 if (isFiniteNumber(value)) {84 return value85 }8687 if (typeof value === "string" && value.trim() !== "") {88 const next = Number(value)89 return Number.isFinite(next) ? next : undefined90 }9192 return undefined93}9495function getRowKeys(data: ChartsProps["data"]) {96 const keys = new Set<string>()9798 for (const row of data) {99 Object.keys(row).forEach((key) => keys.add(key))100 }101102 return Array.from(keys)103}104105function getNumericKeys(data: ChartsProps["data"], keys: string[]) {106 return keys.filter((key) =>107 data.some((row) => toFiniteNumber(row[key]) !== undefined)108 )109}110111function getTextKeys(data: ChartsProps["data"], keys: string[]) {112 return keys.filter((key) =>113 data.some((row) => {114 const value = row[key]115 return typeof value === "string" && value.trim() !== ""116 })117 )118}119120function titleizeKey(key: string) {121// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from fable-ui
All 10 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| DataBrowserdata-browser | fable-ui | Blocks | Free | 4 deps · 21 files | |
| Fable UI Quickstartquickstart | fable-ui | Blocks | Free | 11 deps · 8 files |
