Data Visualization
What This Does
Creates effective data visualizations — from simple charts to interactive dashboards. Covers library selection, chart type choice, design best practices, and implementation patterns for web applications. Supports D3.js, Chart.js, Tremor, Recharts, Nivo, and other popular libraries.
Instructions
Understand the data and audience. Clarify:
- What data is being visualized? (time series, categories, relationships, geographic)
- Who is the audience? (executives, analysts, engineers, customers)
- What question should the visualization answer?
- What actions should the viewer take based on the data?
- Interactive or static? Dashboard or single chart?
Choose the right chart type.
| Data Type |
Best Chart |
When to Use |
| Trend over time |
Line chart |
Show change over continuous time |
| Comparison |
Bar chart (horizontal for many items) |
Compare discrete categories |
| Composition |
Stacked bar / pie (max 5 slices) |
Show parts of a whole |
| Distribution |
Histogram / box plot |
Show how data is spread |
| Relationship |
Scatter plot |
Show correlation between two variables |
| Flow |
Sankey diagram |
Show movement between stages |
| Geographic |
Choropleth / bubble map |
Location-based data |
| KPI |
Number card / sparkline |
Single metric with context |
Choose the library.
| Library |
Best For |
Framework |
Complexity |
| Tremor |
Business dashboards with React |
React |
Low |
| Recharts |
React apps, standard charts |
React |
Low |
| Chart.js |
Simple charts, any framework |
Vanilla/Any |
Low |
| Nivo |
Beautiful, interactive React charts |
React |
Medium |
| D3.js |
Custom, complex visualizations |
Vanilla |
High |
| Observable Plot |
Quick data exploration |
Vanilla |
Low |
| Plotly |
Scientific/analytical charts |
Python/JS |
Medium |
Implement with Tremor (React, recommended for dashboards).
import { Card, AreaChart, BarList, Metric, Text } from '@tremor/react';
function RevenueDashboard({ data }: { data: RevenueData[] }) {
return (
<div className="grid grid-cols-3 gap-4">
{/* KPI Cards */}
<Card>
<Text>Total Revenue</Text>
<Metric>${formatCurrency(data.totalRevenue)}</Metric>
</Card>
{/* Area Chart - Revenue over time */}
<Card className="col-span-2">
<AreaChart
data={data.monthly}
index="month"
categories={['revenue', 'target']}
colors={['blue', 'gray']}
valueFormatter={formatCurrency}
/>
</Card>
{/* Bar List - Top products */}
<Card>
<Text>Top Products</Text>
<BarList
data={data.topProducts.map(p => ({
name: p.name,
value: p.revenue,
}))}
valueFormatter={formatCurrency}
/>
</Card>
</div>
);
}
Implement with Recharts (React, custom charts).
import {
LineChart, Line, XAxis, YAxis, CartesianGrid,
Tooltip, Legend, ResponsiveContainer
} from 'recharts';
function RevenueChart({ data }: { data: MonthlyData[] }) {
return (
<ResponsiveContainer width="100%" height={400}>
<LineChart data={data}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="month" />
<YAxis tickFormatter={v => `$${v / 1000}k`} />
<Tooltip formatter={v => [`$${v.toLocaleString()}`, 'Revenue']} />
<Legend />
<Line
type="monotone"
dataKey="revenue"
stroke="#3b82f6"
strokeWidth={2}
dot={false}
/>
<Line
type="monotone"
dataKey="target"
stroke="#9ca3af"
strokeDasharray="5 5"
dot={false}
/>
</LineChart>
</ResponsiveContainer>
);
}
Design best practices.
- Label everything: axes, units, data sources, time periods
- Start Y-axis at zero for bar charts (not always for line charts)
- Use color intentionally: one color for one meaning, consistent across views
- Remove chart junk: no 3D effects, no unnecessary gridlines, no decorative elements
- Responsive: use
ResponsiveContainer or CSS-based sizing
- Accessible: include alt text, ensure sufficient color contrast, don't rely on color alone
- Format numbers: use abbreviations for large numbers ($1.2M not $1,234,567)
Output Format
When creating visualizations:
- Provide the component code with TypeScript types
- Include sample data for testing
- Specify which library version is required
- Include responsive container wrapping
- Add proper number formatting
# Visualization: {Chart Name}
## Library
{library}@{version}
## Install
```bash
{install command}
Component
{Full component code}
Sample Data
{TypeScript type + sample data}
Usage
{How to use the component}
## Tips
- Tremor is the fastest path to a professional dashboard — it handles layout, theming, and responsive design
- For dashboards, consistency matters more than individual chart beauty — use one library throughout
- D3 is powerful but overkill for standard charts — use it only when you need custom interactions or unusual chart types
- Always wrap charts in `ResponsiveContainer` (Recharts) or use Tremor's auto-responsive components
- Test with real data volumes — charts that look good with 10 data points may fail with 10,000
- Dark mode support matters — test both light and dark themes
- Consider using server-side rendering for charts that don't need interactivity (faster, SEO-friendly)
1---2name: data-visualization3description: Create charts, dashboards, and data visualizations using D3.js, Chart.js, Tremor, Recharts, and other libraries.4---56# Data Visualization78## What This Does910Creates effective data visualizations — from simple charts to interactive dashboards. Covers library selection, chart type choice, design best practices, and implementation patterns for web applications. Supports D3.js, Chart.js, Tremor, Recharts, Nivo, and other popular libraries.1112## Instructions13141. **Understand the data and audience.** Clarify:15 - What data is being visualized? (time series, categories, relationships, geographic)16 - Who is the audience? (executives, analysts, engineers, customers)17 - What question should the visualization answer?18 - What actions should the viewer take based on the data?19 - Interactive or static? Dashboard or single chart?20212. **Choose the right chart type.**2223 | Data Type | Best Chart | When to Use |24 |-----------|-----------|-------------|25 | Trend over time | Line chart | Show change over continuous time |26 | Comparison | Bar chart (horizontal for many items) | Compare discrete categories |27 | Composition | Stacked bar / pie (max 5 slices) | Show parts of a whole |28 | Distribution | Histogram / box plot | Show how data is spread |29 | Relationship | Scatter plot | Show correlation between two variables |30 | Flow | Sankey diagram | Show movement between stages |31 | Geographic | Choropleth / bubble map | Location-based data |32 | KPI | Number card / sparkline | Single metric with context |33343. **Choose the library.**3536 | Library | Best For | Framework | Complexity |37 |---------|----------|-----------|------------|38 | Tremor | Business dashboards with React | React | Low |39 | Recharts | React apps, standard charts | React | Low |40 | Chart.js | Simple charts, any framework | Vanilla/Any | Low |41 | Nivo | Beautiful, interactive React charts | React | Medium |42 | D3.js | Custom, complex visualizations | Vanilla | High |43 | Observable Plot | Quick data exploration | Vanilla | Low |44 | Plotly | Scientific/analytical charts | Python/JS | Medium |45464. **Implement with Tremor (React, recommended for dashboards).**47 ```tsx48 import { Card, AreaChart, BarList, Metric, Text } from '@tremor/react';4950 function RevenueDashboard({ data }: { data: RevenueData[] }) {51 return (52 <div className="grid grid-cols-3 gap-4">53 {/* KPI Cards */}54 <Card>55 <Text>Total Revenue</Text>56 <Metric>${formatCurrency(data.totalRevenue)}</Metric>57 </Card>5859 {/* Area Chart - Revenue over time */}60 <Card className="col-span-2">61 <AreaChart62 data={data.monthly}63 index="month"64 categories={['revenue', 'target']}65 colors={['blue', 'gray']}66 valueFormatter={formatCurrency}67 />68 </Card>6970 {/* Bar List - Top products */}71 <Card>72 <Text>Top Products</Text>73 <BarList74 data={data.topProducts.map(p => ({75 name: p.name,76 value: p.revenue,77 }))}78 valueFormatter={formatCurrency}79 />80 </Card>81 </div>82 );83 }84 ```85865. **Implement with Recharts (React, custom charts).**87 ```tsx88 import {89 LineChart, Line, XAxis, YAxis, CartesianGrid,90 Tooltip, Legend, ResponsiveContainer91 } from 'recharts';9293 function RevenueChart({ data }: { data: MonthlyData[] }) {94 return (95 <ResponsiveContainer width="100%" height={400}>96 <LineChart data={data}>97 <CartesianGrid strokeDasharray="3 3" />98 <XAxis dataKey="month" />99 <YAxis tickFormatter={v => `$${v / 1000}k`} />100 <Tooltip formatter={v => [`$${v.toLocaleString()}`, 'Revenue']} />101 <Legend />102 <Line103 type="monotone"104 dataKey="revenue"105 stroke="#3b82f6"106 strokeWidth={2}107 dot={false}108 />109 <Line110 type="monotone"111 dataKey="target"112 stroke="#9ca3af"113 strokeDasharray="5 5"114 dot={false}115 />116 </LineChart>117 </ResponsiveContainer>118 );119 }120 ```1211226. **Design best practices.**123 - **Label everything:** axes, units, data sources, time periods124 - **Start Y-axis at zero** for bar charts (not always for line charts)125 - **Use color intentionally:** one color for one meaning, consistent across views126 - **Remove chart junk:** no 3D effects, no unnecessary gridlines, no decorative elements127 - **Responsive:** use `ResponsiveContainer` or CSS-based sizing128 - **Accessible:** include alt text, ensure sufficient color contrast, don't rely on color alone129 - **Format numbers:** use abbreviations for large numbers ($1.2M not $1,234,567)130131## Output Format132133When creating visualizations:134- Provide the component code with TypeScript types135- Include sample data for testing136- Specify which library version is required137- Include responsive container wrapping138- Add proper number formatting139140```markdown141# Visualization: {Chart Name}142143## Library144{library}@{version}145146## Install147```bash148{install command}149```150151## Component152{Full component code}153154## Sample Data155{TypeScript type + sample data}156157## Usage158{How to use the component}159```160161## Tips162163- Tremor is the fastest path to a professional dashboard — it handles layout, theming, and responsive design164- For dashboards, consistency matters more than individual chart beauty — use one library throughout165- D3 is powerful but overkill for standard charts — use it only when you need custom interactions or unusual chart types166- Always wrap charts in `ResponsiveContainer` (Recharts) or use Tremor's auto-responsive components167- Test with real data volumes — charts that look good with 10 data points may fail with 10,000168- Dark mode support matters — test both light and dark themes169- Consider using server-side rendering for charts that don't need interactivity (faster, SEO-friendly)