# ChartKit - Complete API Reference for AI Assistants > @derpdaderp/chartkit v0.4.1 > Lightweight React charting library with 14 components and 17 themes. > Zero dependencies, pure SVG, ~15KB gzipped. ## Installation ```bash npm install @derpdaderp/chartkit ``` --- ## COMPONENTS ### Sparkline Minimal inline trend chart. Responsive by default. ```tsx import { Sparkline } from '@derpdaderp/chartkit'; ``` Example: ```tsx ``` --- ### MiniArea Small area chart with gradient fill. Responsive by default. ```tsx import { MiniArea } from '@derpdaderp/chartkit'; ``` --- ### LineChart Feature-rich line chart with dual Y-axis, curve types, and area fills. ```tsx import { LineChart } from '@derpdaderp/chartkit'; // SeriesConfig interface SeriesConfig { key: string; // Data property key label: string; // Display label displayValue?: string; // Badge value in legend yAxisId?: 'left'|'right'; // Y-axis assignment (default: 'left') area?: boolean; // Fill area under line areaOpacity?: number; // Area fill opacity (default: 0.15) color?: string; // Custom line color strokeDasharray?: string; // Dash pattern (e.g., "5,5") strokeWidth?: number; // Line width (default: 2) } // YAxisConfig interface YAxisConfig { unit?: string; // Unit label (e.g., "ms", "req/s") min?: number; // Minimum value (auto if not set) max?: number; // Maximum value (auto if not set) tickCount?: number; // Number of ticks (default: 3) format?: (v: number) => string; // Custom tick formatter } // CurveType type CurveType = 'linear' | 'monotone' | 'step' | 'stepBefore' | 'stepAfter'; // GridOptions interface GridOptions { horizontal?: boolean; // Default: true vertical?: boolean; // Default: false strokeDasharray?: string; // Default: "4,4" color?: string; // Override theme grid color opacity?: number; // 0-1 strokeWidth?: number; // Default: 1 } ``` Example - Basic: ```tsx ``` Example - Multi-series with smooth curves: ```tsx ``` Example - Dual Y-axis: ```tsx ``` Example - Area chart: ```tsx ``` --- ### BarChart Grouped bar chart with optional annotations. ```tsx import { BarChart } from '@derpdaderp/chartkit'; ``` --- ### DonutChart Pie/donut chart with optional center content. ```tsx import { DonutChart } from '@derpdaderp/chartkit'; ``` --- ### KpiCard Metric card with sparkline and delta indicator. ```tsx import { KpiCard } from '@derpdaderp/chartkit'; string} // Optional. Value formatter sparklineColor={string} // Optional. Override sparkline color /> ``` Example: ```tsx `$${(v/1000).toFixed(0)}K`} /> ``` --- ### ProgressRing Circular progress indicator. ```tsx import { ProgressRing } from '@derpdaderp/chartkit'; ``` --- ### GaugeChart Semicircular gauge with optional ranges. ```tsx import { GaugeChart } from '@derpdaderp/chartkit'; // GaugeRange interface GaugeRange { min: number; max: number; color: string; label?: string; } ``` --- ### ScatterChart Scatter plot with optional bubble sizing and logarithmic scales. ```tsx import { ScatterChart } from '@derpdaderp/chartkit'; // ScaleType type ScaleType = 'linear' | 'log'; ``` Example with log scales (great for exponential data): ```tsx ``` --- ### ComboChart Combined line, bar, and area chart with dual Y-axes. ```tsx import { ComboChart } from '@derpdaderp/chartkit'; // ComboSeriesConfig interface ComboSeriesConfig { key: string; label: string; type: 'line' | 'bar' | 'area'; color?: string; } ``` --- ### StackedArea Stacked area chart with interactive legend. ```tsx import { StackedArea } from '@derpdaderp/chartkit'; // SeriesConfig for StackedArea interface SeriesConfig { key: string; // Data property key label: string; // Display label color?: string; // Optional custom color } ``` Example: ```tsx ``` --- ### Heatmap GitHub-style activity grid. ```tsx import { Heatmap } from '@derpdaderp/chartkit'; // HeatmapDataPoint interface HeatmapDataPoint { date: string; // ISO date string (YYYY-MM-DD) value: number; // Activity value (0 = empty) } ``` --- ### SpikeChart Event spike visualization. ```tsx import { SpikeChart } from '@derpdaderp/chartkit'; ``` --- ### CandlestickChart Financial OHLC candlestick chart with zoom, pan, and optional volume. ```tsx import { CandlestickChart } from '@derpdaderp/chartkit'; string} // Optional. Y-axis formatter upColor={string} // Optional. Bullish candle color downColor={string} // Optional. Bearish candle color /> ``` Data format: ```tsx const stockData = [ { time: 'Jan 1', open: 100, high: 105, low: 98, close: 103, volume: 1000000 }, { time: 'Jan 2', open: 103, high: 108, low: 102, close: 106, volume: 1200000 }, // ... ]; ``` Features: - Mouse wheel to zoom in/out - Click and drag to pan - Crosshair cursor on hover - Optional volume histogram Example: ```tsx `$${v.toFixed(2)}`} /> ``` --- ## UTILITY COMPONENTS ### ResponsiveChart Auto-sizing wrapper that provides width/height to children. ```tsx import { ResponsiveChart } from '@derpdaderp/chartkit'; {({ width, height }) => ( )} ``` ### Legend Standalone interactive legend component. ```tsx import { Legend } from '@derpdaderp/chartkit'; // LegendItem interface LegendItem { key: string; label: string; color: string; visible?: boolean; } ``` ### Annotations Reference lines and areas overlay (used internally, can be standalone). ```tsx // Annotations are typically passed as props to charts: ``` --- ## HOOKS ### useAutoTheme Automatically switch themes based on dark/light mode. ```tsx import { useAutoTheme } from '@derpdaderp/chartkit'; const theme = useAutoTheme({ light: ThemeName, // Required. Theme for light mode dark: ThemeName, // Required. Theme for dark mode selector?: string, // Default: 'html'. DOM element to observe darkClass?: string, // Default: 'dark'. Class indicating dark mode useSystemPreference?: boolean, // Default: false. Use OS preference instead }); ``` Example: ```tsx const theme = useAutoTheme({ light: 'sunset', dark: 'neon' }); ``` --- ### useContainerWidth Track container width for responsive sizing. ```tsx import { useContainerWidth } from '@derpdaderp/chartkit'; const { ref, width } = useContainerWidth(); return (
{width > 0 && }
); ``` --- ### useResizeObserver Track both width and height of container. ```tsx import { useResizeObserver } from '@derpdaderp/chartkit'; const { ref, size, ready } = useResizeObserver(); // size = { width: number, height: number } ``` --- ## THEMES ### Dark Themes (13) | Name | Description | |------|-------------| | midnight | Deep black, cyan accent | | emerald | Black, green accent | | mono | Pure black, white accent | | slate | Blue-gray, blue accent | | arctic | Cold blue palette | | orchid | Purple accent | | obsidian | Deep dark, blue accent | | neon | Vibrant city lights | | mocha | Warm pastel dark | | owl | Deep blue | | retro | 80s neon pink | | copper | Warm earth tones | | rose | Pink/rose accent | ### Light Themes (4) | Name | Description | |------|-------------| | sunset | White, orange accent | | silver | White, blue accent | | pearl | Warm ivory | | latte | Creamy pastel | --- ## TYPES ### Annotation ```tsx type Annotation = ReferenceLine | ReferenceArea; interface ReferenceLine { type: 'line'; value: number; axis: 'x' | 'y'; color?: string; strokeDasharray?: string; label?: string; } interface ReferenceArea { type: 'area'; start: number; end: number; axis: 'x' | 'y'; color?: string; opacity?: number; label?: string; } ``` ### ThemeName ```tsx type ThemeName = | 'midnight' | 'emerald' | 'mono' | 'slate' | 'arctic' | 'orchid' | 'obsidian' | 'neon' | 'mocha' | 'owl' | 'retro' | 'copper' | 'rose' | 'sunset' | 'silver' | 'pearl' | 'latte'; ``` --- ## LINKS - Documentation: https://chartkit.dev - npm: https://www.npmjs.com/package/@derpdaderp/chartkit - GitHub: https://github.com/toddynho/chartkit - LLM Reference: https://chartkit.dev/llms.txt