observable-plot-react
Create production-ready data visualizations using Observable Plot in React/Next.js applications. Build interactive charts, maps, and statistical graphics from Parquet data with TypeScript support. Export to SVG/JSON for deployment.
Observable Plot for React/Next.js
Create high-quality, interactive data visualizations using Observable Plot in React and Next.js applications with full TypeScript support.
When to Use This Skill
Use this skill when you need to:
- Build data visualizations in React/Next.js applications
- Create interactive charts and maps from Parquet files
- Generate publication-quality statistical graphics
- Export visualizations as SVG/JSON for deployment
- Implement complex multi-layered compositions
- Create geographic visualizations (choropleth maps, bubble maps)
- Build time series, scatter plots, heatmaps, and density plots
Key indicators:
- User mentions "Observable Plot", "Plot.js", or "data visualization in React"
- Request involves Parquet data processing
- Need for both Node.js generation and React rendering
- Creating static exports (SVG/JSON) for Next.js/Vercel deployment
- TypeScript-based visualization components required
Prerequisites
Core dependencies:
UI components (if using shadcn/ui):
System requirements:
- Node.js 18+
- React 18+
- Next.js 13+ (for App Router components)
- TypeScript 5+
Bundled Resources
References (references/)
Load this comprehensive guide when implementing Observable Plot visualizations:
- plot-guide.md - Complete Observable Plot guide covering:
- Installation and setup
- Reading Parquet files with Apache Arrow and DuckDB
- Core concepts and architecture
- Chart patterns (scatter, line, bar, area, heatmap, density)
- Geographic visualizations (choropleth, bubble maps)
- Data transformations and aggregations
- Exporting to SVG/JSON
- React integration patterns
- Performance optimization
- Troubleshooting common issues
Assets (assets/)
Production-ready React/TypeScript components organized by type:
Maps (assets/maps/):
- BubbleMap.tsx - US county bubble map with population sizing
- ChoroplethMap.tsx - Choropleth map with color scales
- EuropeMap.tsx - European geographic visualization
- geo.state_map.v1.tsx - US state-level map component
- ZipMap.tsx - ZIP code-level mapping
Charts (assets/charts/):
- LineChart.tsx - Time series line charts with confidence intervals
- TimeTrendDemo.tsx - Trend visualization with multiple series
- timeseries.grouped.v1.tsx - Grouped time series comparisons
- PlotBar.tsx - Standard bar charts
- SplitBar.tsx - Split/stacked bar charts
- stat.splitbar.v1.tsx - Statistical split bar variant
Specialized (assets/specialized/):
- CorrelationHeatmap.tsx - Correlation matrix heatmap
- matrix.heatmap.v1.tsx - General matrix heatmap
- DensityPlot.tsx - 2D density visualization
- DotPlot.tsx - Dot plot for distributions
- HealthScatterplot.tsx - Scatterplot with health data patterns
Core Workflow
Step 1: Choose Visualization Type
Geographic Maps:
- Choropleth maps for regional data
- Bubble maps for point data with size encoding
- State/county level visualizations
- See
assets/maps/
Time Series:
- Line charts with confidence intervals
- Multi-series comparisons
- Trend analysis
- See
assets/charts/LineChart.tsx,TimeTrendDemo.tsx
Statistical Graphics:
- Correlation heatmaps
- Density plots
- Dot plots for distributions
- Scatterplots with regression
- See
assets/specialized/
Categorical Data:
- Bar charts (horizontal/vertical)
- Split/stacked bars
- Grouped comparisons
- See
assets/charts/PlotBar.tsx,SplitBar.tsx
Step 2: Data Preparation
From Parquet files:
Using DuckDB:
Step 3: Build React Component
Basic pattern:
Step 4: Export for Deployment
Export to SVG:
Export to JSON:
Common Patterns
Pattern 1: Time Series with Confidence Intervals
Pattern 2: Choropleth Map
Pattern 3: Correlation Heatmap
Pattern 4: Density Plot
TypeScript Integration
Define Interfaces
Type-Safe Plot Configuration
Performance Optimization
1. Memoize Expensive Computations
2. Lazy Loading for Large Datasets
3. Disable Animations for Performance
Next.js Integration
Server Component (Generate SVG)
Client Component (Interactive)
Troubleshooting
Issue 1: "document is not defined" (Server-Side)
Solution: Use JSDOM for server-side rendering
Issue 2: React Hydration Mismatch
Solution: Use 'use client' directive
Issue 3: TopoJSON Not Loading
Solution: Ensure proper data fetching
Issue 4: SVG Not Displaying
Solution: Check container ref and cleanup
Best Practices
1. Always Use TypeScript Interfaces
Define clear data structures for type safety and autocomplete.
2. Implement Proper Error Handling
3. Use Responsive Dimensions
4. Optimize Data Before Rendering
Filter and aggregate data before passing to Plot.
5. Use Proper Cleanup
Always remove plots in useEffect cleanup to prevent memory leaks.
Example Project Structure
my-app/
├── app/
│ ├── charts/
│ │ └── page.tsx # Chart pages
│ └── api/
│ └── data/
│ └── route.ts # API routes for data
├── components/
│ └── charts/
│ ├── LineChart.tsx
│ ├── ChoroplethMap.tsx
│ └── ...
├── lib/
│ ├── data.ts # Data fetching utilities
│ └── plot-utils.ts # Plot helper functions
└── public/
└── data/
├── us-counties.json
└── *.parquet
Resources
- Observable Plot Documentation: https://observablehq.com/plot/
- Observable Plot Examples: https://observablehq.com/@observablehq/plot-gallery
- TopoJSON: https://github.com/topojson/topojson
- Parquet-WASM: https://github.com/kylebarron/parquet-wasm
See Also
Comprehensive Guide:
references/plot-guide.md- Complete Observable Plot guide with all patterns
Component Templates by Type:
assets/maps/- Geographic visualizationsassets/charts/- Standard chart typesassets/specialized/- Statistical graphics