---
name: bubble-chart
description: Build BubbleChart components. Use for scatter plots with size encoding, showing relationships between three variables.
---
# BubbleChart
BubbleChart displays data points as circles where position (x, y) and size encode three different variables. Great for showing relationships and clusters.
## Mental Model
```
┌─────────────────────────────────────────────────────────────┐
│ THREE DIMENSIONS OF DATA │
│ │
│ Y-Axis │
│ ▲ ◯ large │
│ │ ● (size = third variable) │
│ │ ◉ │
│ │ ● ◯ │
│ │ ◉ │
│ │ small ● │
│ └──────────────────────► X-Axis │
│ │
│ • xAccessor: horizontal position │
│ • yAccessor: vertical position │
│ • sizeAccessor: bubble size │
│ • categoryKey: bubble color │
└─────────────────────────────────────────────────────────────┘
```
## Complete Example
```vue
```
## Key Props Reference
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `data` | `T[]` | required | Array of data objects |
| `categories` | `Record` | required | Color mapping for categoryKey values |
| `categoryKey` | `keyof T` | required | Data key for bubble coloring |
| `xAccessor` | `(d: T) => number` | - | Function to get x-position |
| `yAccessor` | `(d: T) => number` | - | Function to get y-position |
| `sizeAccessor` | `(d: T) => number` | - | Function to get bubble size |
| `sizeRange` | `[number, number]` | `[1, 20]` | Min/max bubble radius in pixels |
| `opacity` | `number` | - | Bubble opacity (0-1) |
| `height` | `number` | required | Chart height in pixels |
| `xFormatter` | `(tick, i?, ticks?) => string` | - | X-axis label formatter |
| `yFormatter` | `(tick, i?, ticks?) => string` | - | Y-axis label formatter |
| `labelPosition` | `Position` | `Bottom` | Position of bubble labels |
| `xLabel` | `string` | - | X-axis title |
| `yLabel` | `string` | - | Y-axis title |
| `hideLegend` | `boolean` | `false` | Hide the legend |
| `hideTooltip` | `boolean` | `false` | Hide tooltips |
| `xGridLine` | `boolean` | `false` | Show vertical grid lines |
| `yGridLine` | `boolean` | `false` | Show horizontal grid lines |
## Common Patterns
### Simple Scatter Plot (No Size Variation)
```vue
```
### Performance Matrix
```vue
```
## Accessors Explained
```typescript
// Accessors are functions that extract values from each data item
const data = [
{ name: 'A', sales: 100, profit: 20, marketShare: 15 }
]
// Each accessor takes a data item and returns a number
const xAccessor = (d) => d.sales // position on x-axis
const yAccessor = (d) => d.profit // position on y-axis
const sizeAccessor = (d) => d.marketShare // bubble size
```
## Gotchas
1. **categoryKey is required**: Unlike other charts, you must specify which data key determines bubble color
2. **Categories must cover all values**: Every unique value in categoryKey must have a category entry
3. **sizeRange affects perception**: Use reasonable ranges; too large bubbles overlap, too small are invisible
4. **Accessors return numbers**: Make sure accessor functions return numeric values, not strings
5. **Opacity helps overlapping**: Use `opacity` prop when bubbles might overlap