Scatter chart
Plot two measures against each other, one point per dimension value.
Preview
Revenue vs seats
Usage
import {
ChartsProvider,
ScatterChart,
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 },
});
export const Example = () => (
<ChartsProvider>
<div style={{ height: 360 }}>
<ScatterChart
title="Revenue vs seats"
pointDimension={account}
groupByDimension={plan}
xMeasure={seats}
yMeasure={revenue}
results={results(rows)}
showValueLabels={false}
/>
</div>
</ChartsProvider>
);
const rows = [
{ account: 'Alder', plan: 'Starter', seats: 40, revenue: 44000 },
{ account: 'Birch', plan: 'Starter', seats: 66, revenue: 60000 },
{ account: 'Cedar', plan: 'Starter', seats: 92, revenue: 49000 },
{ account: 'Dune', plan: 'Growth', seats: 118, revenue: 78000 },
{ account: 'Ember', plan: 'Growth', seats: 144, revenue: 64000 },
{ account: 'Fjord', plan: 'Growth', seats: 170, revenue: 96000 },
{ account: 'Grove', plan: 'Growth', seats: 196, revenue: 84000 },
{ account: 'Harbor', plan: 'Enterprise', seats: 226, revenue: 131000 },
{ account: 'Isle', plan: 'Enterprise', seats: 258, revenue: 114000 },
{ account: 'Juniper', plan: 'Enterprise', seats: 296, revenue: 176000 },
{ account: 'Kite', plan: 'Enterprise', seats: 334, revenue: 152000 },
];- Each row is one point.
groupByDimensioncolours the points and adds the legend.
Install with npm install em-kit. Needs <ChartsProvider> once and a parent with a height: Quick start.
Examples
Point labels
Each point labelled with its dimension value, so outliers name themselves. A label sits under its point, so both axes start at zero here to keep the labels clear of them.
Show full code (49 lines)
import {
ChartsProvider,
ScatterChart,
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 },
});
export const Example = () => (
<ChartsProvider>
<div style={{ height: 360 }}>
<ScatterChart
title="Revenue vs seats"
pointDimension={account}
groupByDimension={plan}
xMeasure={seats}
yMeasure={revenue}
results={results(rows)}
showValueLabels={false}
showPointLabels
xAxisRangeMin={0}
yAxisRangeMin={0}
/>
</div>
</ChartsProvider>
);
const rows = [
{ account: 'Alder', plan: 'Starter', seats: 40, revenue: 44000 },
{ account: 'Birch', plan: 'Starter', seats: 66, revenue: 60000 },
{ account: 'Cedar', plan: 'Starter', seats: 92, revenue: 49000 },
{ account: 'Dune', plan: 'Growth', seats: 118, revenue: 78000 },
{ account: 'Ember', plan: 'Growth', seats: 144, revenue: 64000 },
{ account: 'Fjord', plan: 'Growth', seats: 170, revenue: 96000 },
{ account: 'Grove', plan: 'Growth', seats: 196, revenue: 84000 },
{ account: 'Harbor', plan: 'Enterprise', seats: 226, revenue: 131000 },
{ account: 'Isle', plan: 'Enterprise', seats: 258, revenue: 114000 },
{ account: 'Juniper', plan: 'Enterprise', seats: 296, revenue: 176000 },
{ account: 'Kite', plan: 'Enterprise', seats: 334, revenue: 152000 },
];<ScatterChart
title="Revenue vs seats"
pointDimension={account}
groupByDimension={plan}
xMeasure={seats}
yMeasure={revenue}
results={results(rows)}
showValueLabels={false}
showPointLabels
xAxisRangeMin={0}
yAxisRangeMin={0}
/>One colour
Every point in one colour with no grouping, for a plain correlation plot.
Show full code (46 lines)
import {
ChartsProvider,
ScatterChart,
dimension,
measure,
results,
} from 'em-kit';
const account = dimension({ name: 'account', title: 'Account' });
const seats = measure({ name: 'seats', title: 'Seats' });
const revenue = measure({
name: 'revenue',
title: 'Revenue',
inputs: { currency: 'USD', abbreviateLargeNumber: true },
});
export const Example = () => (
<ChartsProvider>
<div style={{ height: 360 }}>
<ScatterChart
title="Revenue vs seats"
pointDimension={account}
xMeasure={seats}
yMeasure={revenue}
results={results(rows)}
showLegend={false}
showValueLabels={false}
pointColor="#0ea5e9"
/>
</div>
</ChartsProvider>
);
const rows = [
{ account: 'Alder', seats: 40, revenue: 44000 },
{ account: 'Birch', seats: 66, revenue: 60000 },
{ account: 'Cedar', seats: 92, revenue: 49000 },
{ account: 'Dune', seats: 118, revenue: 78000 },
{ account: 'Ember', seats: 144, revenue: 64000 },
{ account: 'Fjord', seats: 170, revenue: 96000 },
{ account: 'Grove', seats: 196, revenue: 84000 },
{ account: 'Harbor', seats: 226, revenue: 131000 },
{ account: 'Isle', seats: 258, revenue: 114000 },
{ account: 'Juniper', seats: 296, revenue: 176000 },
{ account: 'Kite', seats: 334, revenue: 152000 },
];<ScatterChart
title="Revenue vs seats"
pointDimension={account}
xMeasure={seats}
yMeasure={revenue}
results={results(rows)}
showLegend={false}
showValueLabels={false}
pointColor="#0ea5e9"
/>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. | |
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 point, in place of the theme’s. | |
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. |
onPointClick | ( | Called with the clicked point’s dimension value and its x and y values.ScatterChartOptionsClickArg = { xMeasureValue: string; yMeasureValue: string; pointDimensionValue: string | undefined; groupByDimensionValue: string | null | undefined; pointDimensionTimeRange: TimeRange; groupByDimensionTimeRange: TimeRange; } | |
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
ScatterChart reads only the common options in a field’s inputs.