Bubble chart
A scatter chart with a third measure encoded as bubble size.
Preview
Revenue vs seats, sized by tickets
Usage
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.
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.
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.
| Prop | Type | Default | Description |
|---|---|---|---|
pointDimensionrequired | Dimension | The dimension that names each point, used in the tooltip and the point label. | |
xMeasurerequired | Measure | The measure plotted along the x-axis. | |
yMeasurerequired | Measure | The measure plotted along the y-axis. | |
bubbleSizeMeasurerequired | Measure | A third measure, drawn as the size of each bubble. | |
resultsrequired | DataResponse | Your query’s state: { isLoading, data, error }, where data is your rows. results(rows) builds it from an array. | |
groupByDimension | Dimension | An optional dimension that colours the points by group. | |
pointColor | string | One colour for every bubble, in place of the theme’s. Only read when groupByDimension is not set. | |
showLegend | boolean | true | Show the legend. A chart with one series shows none; entries wrap onto more lines when they do not fit. |
showTooltips | boolean | true | Show a formatted tooltip on hover. |
showPointLabels | boolean | false | Label each point with its pointDimension value. |
showValueLabels | boolean | true | Print each value on the chart. |
showLogarithmicScale | boolean | false | Use a logarithmic value axis, for values that span several orders of magnitude. |
xAxisLabel | string | A title under the x-axis. | |
yAxisLabel | string | A title beside the y-axis. | |
xAxisRangeMin | number | Fix 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. | |
xAxisRangeMax | number | Fix the highest value on the x-axis. When unset, it fits the data. | |
yAxisRangeMin | number | Fix 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. | |
yAxisRangeMax | number | Fix the highest value on the y-axis. When unset, it fits the data. | |
reverseXAxis | boolean | false | Reverse the order of the x-axis. |
bubbleRadiusMin | number | 3 | Radius in pixels of the smallest bubble. |
bubbleRadiusMax | number | 20 | Radius in pixels of the largest bubble. |
onPointClick | ( | Called 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; } | |
componentName | string | A name for this component, included in the interaction events it dispatches on the DOM, for your analytics. | |
trackingId | string | An id included in the same events, to tell two instances apart. | |
title | string | The card’s title. A "key|fallback" string is looked up in your translations. | |
description | string | Smaller text under the title. Translates like title. | |
tooltip | string | Text for an info icon beside the title. | |
hideMenu | boolean | false | Hide the card’s header: the title, description and menu. |
menuOptions | ( | ["csv", | Which entries the card menu offers. Pass [] for none. |
A blank default means the prop is unset unless you pass it.
| Type | Definition |
|---|---|
TimeRange | { from: Date |What a click’s TimeRange holds: Events. |
Field options
BubbleChart reads only the common options in a field’s inputs.