Components · Scatter

Bubble chart

A scatter chart with a third measure encoded as bubble size.

Open in playground

Preview

Revenue vs seats, sized by tickets

Usage

tsx
import {
  ChartsProvider,
  BubbleChart,
  dimension,
  measure,
  results,
} from 'em-kit';

const account = dimension({ name: 'account', title: 'Account' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const seats = measure({ name: 'seats', title: 'Seats' });
const revenue = measure({
  name: 'revenue',
  title: 'Revenue',
  inputs: { currency: 'USD', abbreviateLargeNumber: true },
});
const tickets = measure({ name: 'tickets', title: 'Tickets' });

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 360 }}>
      <BubbleChart
        title="Revenue vs seats, sized by tickets"
        pointDimension={account}
        groupByDimension={plan}
        xMeasure={seats}
        yMeasure={revenue}
        bubbleSizeMeasure={tickets}
        results={results(rows)}
        bubbleRadiusMin={4}
        bubbleRadiusMax={11}
        xAxisRangeMin={0}
        yAxisRangeMin={0}
        showValueLabels={false}
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { account: 'Alder', plan: 'Starter', seats: 40, revenue: 44000, tickets: 6 },
  { account: 'Birch', plan: 'Starter', seats: 66, revenue: 60000, tickets: 14 },
  { account: 'Cedar', plan: 'Starter', seats: 92, revenue: 49000, tickets: 9 },
  { account: 'Dune', plan: 'Growth', seats: 118, revenue: 78000, tickets: 22 },
  { account: 'Ember', plan: 'Growth', seats: 144, revenue: 64000, tickets: 12 },
  { account: 'Fjord', plan: 'Growth', seats: 170, revenue: 96000, tickets: 31 },
  { account: 'Grove', plan: 'Growth', seats: 196, revenue: 84000, tickets: 17 },
  { account: 'Harbor', plan: 'Enterprise', seats: 226, revenue: 131000, tickets: 26 },
  { account: 'Isle', plan: 'Enterprise', seats: 258, revenue: 114000, tickets: 48 },
  { account: 'Juniper', plan: 'Enterprise', seats: 296, revenue: 176000, tickets: 35 },
  { account: 'Kite', plan: 'Enterprise', seats: 334, revenue: 152000, tickets: 58 },
];

Install with npm install em-kit. Needs <ChartsProvider> once and a parent with a height: Quick start.

Examples

Labels

Each bubble labelled with its dimension value.

tsxDiffers from Usage
Show full code (53 lines)
import {
  ChartsProvider,
  BubbleChart,
  dimension,
  measure,
  results,
} from 'em-kit';

const account = dimension({ name: 'account', title: 'Account' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const seats = measure({ name: 'seats', title: 'Seats' });
const revenue = measure({
  name: 'revenue',
  title: 'Revenue',
  inputs: { currency: 'USD', abbreviateLargeNumber: true },
});
const tickets = measure({ name: 'tickets', title: 'Tickets' });

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 360 }}>
      <BubbleChart
        title="Revenue vs seats, sized by tickets"
        pointDimension={account}
        groupByDimension={plan}
        xMeasure={seats}
        yMeasure={revenue}
        bubbleSizeMeasure={tickets}
        results={results(rows)}
        bubbleRadiusMin={4}
        bubbleRadiusMax={11}
        xAxisRangeMin={0}
        yAxisRangeMin={0}
        showValueLabels={false}
        showPointLabels
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { account: 'Alder', plan: 'Starter', seats: 40, revenue: 44000, tickets: 6 },
  { account: 'Birch', plan: 'Starter', seats: 66, revenue: 60000, tickets: 14 },
  { account: 'Cedar', plan: 'Starter', seats: 92, revenue: 49000, tickets: 9 },
  { account: 'Dune', plan: 'Growth', seats: 118, revenue: 78000, tickets: 22 },
  { account: 'Ember', plan: 'Growth', seats: 144, revenue: 64000, tickets: 12 },
  { account: 'Fjord', plan: 'Growth', seats: 170, revenue: 96000, tickets: 31 },
  { account: 'Grove', plan: 'Growth', seats: 196, revenue: 84000, tickets: 17 },
  { account: 'Harbor', plan: 'Enterprise', seats: 226, revenue: 131000, tickets: 26 },
  { account: 'Isle', plan: 'Enterprise', seats: 258, revenue: 114000, tickets: 48 },
  { account: 'Juniper', plan: 'Enterprise', seats: 296, revenue: 176000, tickets: 35 },
  { account: 'Kite', plan: 'Enterprise', seats: 334, revenue: 152000, tickets: 58 },
];
<BubbleChart
  title="Revenue vs seats, sized by tickets"
  pointDimension={account}
  groupByDimension={plan}
  xMeasure={seats}
  yMeasure={revenue}
  bubbleSizeMeasure={tickets}
  results={results(rows)}
  bubbleRadiusMin={4}
  bubbleRadiusMax={11}
  xAxisRangeMin={0}
  yAxisRangeMin={0}
  showValueLabels={false}
  showPointLabels
/>

Wider size range

A wider spread between the smallest and largest bubble, to make the third measure stand out. Both radii are in pixels.

tsxDiffers from Usage
Show full code (52 lines)
import {
  ChartsProvider,
  BubbleChart,
  dimension,
  measure,
  results,
} from 'em-kit';

const account = dimension({ name: 'account', title: 'Account' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const seats = measure({ name: 'seats', title: 'Seats' });
const revenue = measure({
  name: 'revenue',
  title: 'Revenue',
  inputs: { currency: 'USD', abbreviateLargeNumber: true },
});
const tickets = measure({ name: 'tickets', title: 'Tickets' });

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 360 }}>
      <BubbleChart
        title="Revenue vs seats, sized by tickets"
        pointDimension={account}
        groupByDimension={plan}
        xMeasure={seats}
        yMeasure={revenue}
        bubbleSizeMeasure={tickets}
        results={results(rows)}
        bubbleRadiusMin={2}
        bubbleRadiusMax={22}
        xAxisRangeMin={0}
        yAxisRangeMin={0}
        showValueLabels={false}
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { account: 'Alder', plan: 'Starter', seats: 40, revenue: 44000, tickets: 6 },
  { account: 'Birch', plan: 'Starter', seats: 66, revenue: 60000, tickets: 14 },
  { account: 'Cedar', plan: 'Starter', seats: 92, revenue: 49000, tickets: 9 },
  { account: 'Dune', plan: 'Growth', seats: 118, revenue: 78000, tickets: 22 },
  { account: 'Ember', plan: 'Growth', seats: 144, revenue: 64000, tickets: 12 },
  { account: 'Fjord', plan: 'Growth', seats: 170, revenue: 96000, tickets: 31 },
  { account: 'Grove', plan: 'Growth', seats: 196, revenue: 84000, tickets: 17 },
  { account: 'Harbor', plan: 'Enterprise', seats: 226, revenue: 131000, tickets: 26 },
  { account: 'Isle', plan: 'Enterprise', seats: 258, revenue: 114000, tickets: 48 },
  { account: 'Juniper', plan: 'Enterprise', seats: 296, revenue: 176000, tickets: 35 },
  { account: 'Kite', plan: 'Enterprise', seats: 334, revenue: 152000, tickets: 58 },
];
<BubbleChart
  title="Revenue vs seats, sized by tickets"
  pointDimension={account}
  groupByDimension={plan}
  xMeasure={seats}
  yMeasure={revenue}
  bubbleSizeMeasure={tickets}
  results={results(rows)}
  bubbleRadiusMin={2}
  bubbleRadiusMax={22}
  xAxisRangeMin={0}
  yAxisRangeMin={0}
  showValueLabels={false}
/>

Props

Keyboard and screen readers: Accessibility.

PropTypeDefaultDescription
pointDimensionrequiredDimensionThe dimension that names each point, used in the tooltip and the point label.
xMeasurerequiredMeasureThe measure plotted along the x-axis.
yMeasurerequiredMeasureThe measure plotted along the y-axis.
bubbleSizeMeasurerequiredMeasureA third measure, drawn as the size of each bubble.
resultsrequiredDataResponseYour query’s state: { isLoading, data, error }, where data is your rows. results(rows) builds it from an array.
groupByDimensionDimensionAn optional dimension that colours the points by group.
pointColorstringOne colour for every bubble, in place of the theme’s. Only read when groupByDimension is not set.
showLegendbooleantrueShow the legend. A chart with one series shows none; entries wrap onto more lines when they do not fit.
showTooltipsbooleantrueShow a formatted tooltip on hover.
showPointLabelsbooleanfalseLabel each point with its pointDimension value.
showValueLabelsbooleantruePrint each value on the chart.
showLogarithmicScalebooleanfalseUse a logarithmic value axis, for values that span several orders of magnitude.
xAxisLabelstringA title under the x-axis.
yAxisLabelstringA title beside the y-axis.
xAxisRangeMinnumberFix the lowest value on the x-axis. When unset, a horizontal bar chart’s axis includes zero, and a scatter or bubble chart’s fits the data.
xAxisRangeMaxnumberFix the highest value on the x-axis. When unset, it fits the data.
yAxisRangeMinnumberFix the lowest value on the y-axis. When unset, a bar, line or area chart’s axis includes zero, and a scatter or bubble chart’s fits the data.
yAxisRangeMaxnumberFix the highest value on the y-axis. When unset, it fits the data.
reverseXAxisbooleanfalseReverse the order of the x-axis.
bubbleRadiusMinnumber3Radius in pixels of the smallest bubble.
bubbleRadiusMaxnumber20Radius in pixels of the largest bubble.
onPointClick(payload: BubbleChartOptionsClickArg) => voidCalled with the clicked point’s dimension value and its x and y values.BubbleChartOptionsClickArg = { xMeasureValue: string; yMeasureValue: string; pointDimensionValue: string | undefined; groupByDimensionValue: string | null | undefined; pointDimensionTimeRange: TimeRange; groupByDimensionTimeRange: TimeRange; sizeMeasureValue: string; }
componentNamestringA name for this component, included in the interaction events it dispatches on the DOM, for your analytics.
trackingIdstringAn id included in the same events, to tell two instances apart.
titlestringThe card’s title. A "key|fallback" string is looked up in your translations.
descriptionstringSmaller text under the title. Translates like title.
tooltipstringText for an info icon beside the title.
hideMenubooleanfalseHide the card’s header: the title, description and menu.
menuOptions("csv" | "xlsx" | "png" | "maximize")[]["csv", "xlsx", "png", "maximize"]Which entries the card menu offers. Pass [] for none.

A blank default means the prop is unset unless you pass it.

TypeDefinition
TimeRange{ from: Date | undefined; to: Date | undefined; relativeTimeString?: string; } | undefinedWhat a click’s TimeRange holds: Events.

Field options

BubbleChart reads only the common options in a field’s inputs.