ScatterChart

How two measures relate, one dot per item. Add size for a bubble chart and groupBy for colored groups.

Status: beta. Category: Data display.

import { ScatterChart } from '@glyphui/ui/chart'

Exports: ScatterChart.

Notes

  • Always name both axes with xAxis.label and yAxis.label: a scatter has no other labels.
  • Click a legend entry to hide a group. Set name to show each point’s name in the tooltip.

ScatterChart props

PropTypeDefaultDescription
data (required)readonly T[]
title (required)string
x (required)stringField for the horizontal position.
y (required)stringField for the vertical position.
classNamestring
colorsreadonly ChartColorValue[]One color per group, in order.
descriptionReactNode
emptyReactNodeShown when there is no data. Defaults to a short "No data" message.
errorunknownShows an error message in place of the plot, with a retry button when onRetry is set.
groupBystringField that splits points into colored groups with a legend.
heightnumberPlot height in pixels. Default 280.
hiddenGroupsreadonly string[]
hideTitleboolean
loadingbooleanShows a skeleton in place of the plot.
namestringField naming each point, shown in the tooltip.
onHiddenGroupsChange((hidden: string[]) => void)
onPointClick((row: T) => void)
onRetry(() => unknown)
referenceAreasreadonly ChartReferenceArea[]
referenceLinesreadonly ChartReferenceLine[]
showGridboolean
showLegendboolean
sizestringField for the point size. Turns the scatter into a bubble chart.
sizeFormatter((value: number) => string)Formats size in the tooltip.
sizeRangereadonly [number, number]Smallest and largest bubble area in pixels. Default [40, 600].
xAxisChartAxisOptionsAxis titles and tick formatters. Name the axes: a scatter has no other labels.
yAxisChartAxisOptions

Example: Bubble chart

Accounts by seats and MRR, sized by open tickets and grouped by segment.

import { ScatterChart } from '@glyphui/ui/chart'

const accounts = [
  { name: 'Northwind', seats: 42, mrr: 1240, tickets: 3, segment: 'SMB' },
  { name: 'Initech', seats: 18, mrr: 420, tickets: 1, segment: 'SMB' },
  { name: 'Vandelay', seats: 35, mrr: 910, tickets: 6, segment: 'SMB' },
  { name: 'Umbrella', seats: 96, mrr: 2380, tickets: 4, segment: 'Mid-market' },
  { name: 'Contoso', seats: 140, mrr: 3900, tickets: 9, segment: 'Mid-market' },
  { name: 'Soylent', seats: 120, mrr: 2600, tickets: 2, segment: 'Mid-market' },
  { name: 'Globex', seats: 260, mrr: 8200, tickets: 12, segment: 'Enterprise' },
  { name: 'Hooli', seats: 340, mrr: 12900, tickets: 7, segment: 'Enterprise' },
  { name: 'Wayne', seats: 410, mrr: 11200, tickets: 15, segment: 'Enterprise' },
]

export default function Example() {
  return (
    <ScatterChart
      className="w-full"
      title="Accounts by size and revenue"
      description="Bubble size is open support tickets"
      data={accounts}
      x="seats"
      y="mrr"
      size="tickets"
      name="name"
      groupBy="segment"
      xAxis={{ label: 'Seats' }}
      yAxis={{ label: 'MRR', formatter: (v: number) => `${(v / 1000).toFixed(0)}k` }}
    />
  )
}

Live page: https://glyphui.xyz/components/scatter-chart