Components · Scatter

Scatter chart

Plot two measures against each other, one point per dimension value.

Open in playground

Preview

Revenue vs seats

Usage

tsx
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. groupByDimension colours 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.

tsxDiffers from Usage
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.

tsxDiffers from Usage
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.

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.
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 point, in place of the theme’s.
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.
onPointClick(payload: ScatterChartOptionsClickArg) => voidCalled 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; }
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

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