Command Palette

Search for a command to run...

Docs
Bubble Chart

Bubble Chart

A versatile bubble chart component for visualizing three-dimensional data with position (x, y) and size (z) dimensions. Includes multiple variants with labels, legends, grouping, and interactive features.

Installation

Usage

import {
  BubbleChart,
  BubbleLabelChart,
  BubbleLegendChart,
  BubbleGroupedChart,
  BubbleInteractiveChart,
  BubbleSizeLegendChart,
} from "@/components/ruixen/bubble-chart";
const data = [
  { name: "Prod A", x: 100, y: 200, z: 400 },
  { name: "Prod B", x: 120, y: 100, z: 260 },
  { name: "Prod C", x: 170, y: 300, z: 400 },
  { name: "Prod D", x: 140, y: 250, z: 280 },
]
 
// Default bubble chart
<BubbleChart data={data} xLabel="Units" yLabel="Revenue" zLabel="Share" className="h-[300px]" />
 
// With labels inside bubbles
<BubbleLabelChart data={data} xLabel="Units" yLabel="Revenue" zLabel="Share" className="h-[300px]" />
 
// With legend
<BubbleLegendChart data={data} xLabel="Units" yLabel="Revenue" zLabel="Share" className="h-[320px]" />
 
// Grouped by category
<BubbleGroupedChart data={categoryData} xLabel="Growth" yLabel="Pop" zLabel="Revenue" className="h-[320px]" />
 
// Interactive with hover effects
<BubbleInteractiveChart data={data} xLabel="Week" yLabel="Sales" zLabel="Customers" className="h-[300px]" />
 
// With size legend
<BubbleSizeLegendChart data={data} xLabel="Growth" yLabel="Revenue" zLabel="Employees" className="h-[320px]" />

Examples

Default Bubble

The default bubble chart displays data points as circles with size proportional to the z value.

<BubbleChart
  data={salesData}
  xLabel="Units"
  yLabel="Revenue"
  zLabel="Market Share"
  className="h-[300px]"
/>

With Labels

Display labels inside each bubble for easy identification.

<BubbleLabelChart
  data={performanceData}
  xLabel="Efficiency"
  yLabel="Quality"
  zLabel="Team Size"
  className="h-[300px]"
/>

With Legend

Add a legend showing each data point's name and color.

<BubbleLegendChart
  data={marketData}
  xLabel="Growth %"
  yLabel="Revenue"
  zLabel="Employees"
  legendPosition="bottom"
  className="h-[320px]"
/>

Grouped by Category

Group bubbles by category with different colors per group.

const categoryData = [
  { name: "NYC", x: 40, y: 8500, z: 850, category: "East" },
  { name: "Boston", x: 35, y: 4200, z: 420, category: "East" },
  { name: "LA", x: 55, y: 7200, z: 720, category: "West" },
  { name: "Seattle", x: 48, y: 4800, z: 480, category: "West" },
]
 
<BubbleGroupedChart
  data={categoryData}
  xLabel="Growth %"
  yLabel="Population"
  zLabel="Revenue"
  className="h-[320px]"
/>

Interactive

Enable hover effects to highlight individual bubbles.

<BubbleInteractiveChart
  data={quarterlyData}
  xLabel="Week"
  yLabel="Sales"
  zLabel="Customers"
  className="h-[300px]"
/>

Size Legend

Display a size legend showing the relationship between bubble size and z values.

<BubbleSizeLegendChart
  data={marketData}
  xLabel="Growth %"
  yLabel="Revenue"
  zLabel="Employees"
  className="h-[320px]"
/>

Tooltip Indicators

The component supports three tooltip indicator styles matching shadcn/ui charts:

// Dot indicator (default)
<BubbleChart data={data} tooltipIndicator="dot" />
 
// Line indicator
<BubbleChart data={data} tooltipIndicator="line" />
 
// Dashed indicator
<BubbleChart data={data} tooltipIndicator="dashed" />

Custom Value Formatter

Format values with a custom function:

<BubbleChart
  data={data}
  valueFormatter={(value) => `$${value.toLocaleString()}`}
/>

Props

BubbleChart

PropTypeDefaultDescription
dataBubbleDataItem[]RequiredArray of data items with x, y, z values
classNamestring-Additional CSS classes
showTooltipbooleantrueShow tooltip on hover
tooltipIndicator"dot" | "line" | "dashed""dot"Tooltip indicator style
xLabelstring"X"Label for X axis values
yLabelstring"Y"Label for Y axis values
zLabelstring"Size"Label for Z (size) values
valueFormatter(value: number) => string-Custom value formatter
showXAxisbooleantrueShow X axis
showYAxisbooleantrueShow Y axis
showGridbooleantrueShow grid lines
minBubbleSizenumber60Minimum bubble size (area in pixels)
maxBubbleSizenumber400Maximum bubble size (area in pixels)

BubbleLabelChart

Same props as BubbleChart. Displays labels inside each bubble.

BubbleLegendChart

PropTypeDefaultDescription
legendPosition"top" | "bottom""bottom"Legend position

Plus all BubbleChartBaseProps.

BubbleGroupedChart

Same base props. Groups bubbles by the category field in data items.

BubbleInteractiveChart

Same base props. Adds hover highlighting effect.

BubbleSizeLegendChart

Same base props. Displays a size legend showing min, mid, and max bubble sizes.

BubbleDataItem

PropertyTypeDescription
namestringData point name (displayed in tooltip)
xnumberX-axis value (horizontal position)
ynumberY-axis value (vertical position)
znumberZ value (determines bubble size)
categorystringOptional category for grouping