Choose Right Chart
Choose Right Chart
Technical Explanation
Different chart types serve different purposes. Choosing the wrong chart can obscure insights or create confusion.
Chart Selection Guide
| Data Type | Best Chart | Avoid |
|---|---|---|
| Trend over time | Line | Pie |
| Part to whole | Pie, Stacked Bar | Line |
| Comparison | Bar | Pie |
| Distribution | Histogram, Box | Pie |
| Relationship | Scatter | Bar |
| Single KPI | Number + Trend | Table |
Common Chart Mistakes
- Using pie charts for many categories (>5)
- Using line charts for categories without time
- Using bar charts with inconsistent scales
- 3D charts (distort perception)
Code Examples
Using the CatCafe dataset:
-- Data for different chart types
-- LINE CHART: Revenue trend over time
SELECT
DATE_TRUNC('month', order_date) as month,
SUM(total_amount) as revenue
FROM orders
WHERE status = 'completed'
GROUP BY DATE_TRUNC('month', order_date)
ORDER BY month;
-- BAR CHART: Revenue by category
SELECT
category,
SUM(total_amount) as revenue
FROM products
GROUP BY category
ORDER BY revenue DESC;
-- PIE CHART: Order distribution (only if <5 categories)
SELECT
status,
COUNT(*) as orders
FROM orders
GROUP BY status;
-- Only works well for 2-4 categories
-- STACKED BAR: Revenue by segment over time
SELECT
DATE_TRUNC('month', order_date) as month,
segment,
SUM(total_amount) as revenue
FROM orders o
JOIN customers c ON o.customer_id = c.id
WHERE status = 'completed'
GROUP BY DATE_TRUNC('month', order_date), segment
ORDER BY month;
-- SCATTER: Order value vs customer tenure
SELECT
c.customer_tenure_days as x,
o.total_amount as y
FROM orders o
JOIN customers c ON o.customer_id = c.id
WHERE status = 'completed';
-- HISTOGRAM: Distribution of order values
SELECT
WIDTH_BUCKET(total_amount, 0, 500, 10) as bucket,
(WIDTH_BUCKET(total_amount, 0, 500, 10) - 1) * 10 as range_start,
WIDTH_BUCKET(total_amount, 0, 500, 10) * 10 as range_end,
COUNT(*) as orders
FROM orders
GROUP BY WIDTH_BUCKET(total_amount, 0, 500, 10)
ORDER BY bucket;
The Cat Analogy
Choosing how to display cat weight data:
LINE CHART ✓ (Weight over time):
Whiskers' weight:
Jan: 10 lbs ────
Feb: 10.5 lbs ──�──
Mar: 11 lbs ─────
→ Shows trend clearly
PIE CHART ✗ (Weight vs other cats):
How much each cat eats:
Whiskers eats 30% ────┐
Mochi eats 25% │
Luna eats 25% │ Don't do this!
Shadow eats 20% │
→ Hard to compare!
BAR CHART ✓ (Compare cats):
Cats ranked by weight:
Whiskers ████████████ 11 lbs
Mochi ██████████ 9 lbs
Luna ████████ 8 lbs
→ Easy to compare
Exercises
Exercise 1
What chart type would you use for:
- Monthly revenue for the past 12 months
- Revenue split between product categories
- Distribution of order values
- Relationship between customer age and spending
Exercise 2
Why should you avoid pie charts with more than 5 categories?
Exercise 3
What chart would you use to show how revenue by segment has changed over time?
Key Takeaways
- Line charts: Trends over time
- Bar charts: Comparisons between categories
- Pie charts: Part-to-whole (only 2-4 categories)
- Scatter plots: Relationships between variables
- Histograms: Distribution of values
- Avoid 3D charts, they distort perception