Scatter Chart
Points at two values, x and y, both axes numeric — sized by a third: a bubble chart. Names and colors come from the chart's config; the keyboard moves through the points, and the tooltip says their values.
Installation
It has its own entry point, @semantic-components/ui/charts, built on d3-scale d3-shape — an optional peer of ui: install it where you use the component.
ts
import { ScChart, ScChartPlot, ScChartScatter } from '@semantic-components/ui/charts';Usage
import { DecimalPipe } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import { ScChart, ScChartCategoryAxis, type ScChartConfig, ScChartGrid, ScChartPlot, ScChartScatter, ScChartTooltip, ScChartTooltipIndicator, ScChartTooltipItem, ScChartTooltipLabel, ScChartTooltipName, ScChartTooltipPortal, ScChartTooltipProvider, ScChartTooltipValue, ScChartValueAxis,} from '@semantic-components/ui/charts';
@Component({ selector: 'app-scatter-chart-usage-demo', imports: [ ScChart, ScChartPlot, ScChartGrid, ScChartCategoryAxis, ScChartValueAxis, ScChartScatter, ScChartTooltip, ScChartTooltipPortal, ScChartTooltipProvider, DecimalPipe, ScChartTooltipLabel, ScChartTooltipIndicator, ScChartTooltipItem, ScChartTooltipName, ScChartTooltipValue, ], template: ` <div scChart class="aspect-video max-h-72" [config]="config" [data]="data"> <svg scChartPlot categoryKey="name" aria-label="Height and weight of 12 people" > <g scChartGrid [vertical]="true" /> <g scChartCategoryAxis /> <g scChartValueAxis /> <g scChartScatter key="weight" xKey="height" /> </svg> <div scChartTooltipProvider> <ng-template scChartTooltipPortal> <div scChartTooltip #tooltip="scChartTooltip"> <div scChartTooltipLabel>{{ tooltip.label() }}</div> @for (item of tooltip.payload(); track item.dataKey) { <div scChartTooltipItem [item]="item"> <span scChartTooltipIndicator></span> <span scChartTooltipName>{{ item.name }}</span> <span scChartTooltipValue>{{ item.value | number }}</span> </div> } </div> </ng-template> </div> </div> `, host: { class: 'block w-full max-w-xl' }, encapsulation: ViewEncapsulation.None,})export class ScatterChartUsageDemo { private readonly data = [ { name: 'Ana', height: 158, weight: 52 }, { name: 'Ben', height: 183, weight: 81 }, { name: 'Chloé', height: 165, weight: 60 }, { name: 'Dev', height: 176, weight: 74 }, { name: 'Emi', height: 162, weight: 55 }, { name: 'Farid', height: 189, weight: 90 }, { name: 'Gus', height: 171, weight: 68 }, { name: 'Hana', height: 168, weight: 63 }, { name: 'Ivo', height: 179, weight: 85 }, { name: 'Jo', height: 155, weight: 49 }, { name: 'Kai', height: 185, weight: 77 }, { name: 'Lea', height: 173, weight: 66 }, ]; private readonly config: ScChartConfig = { height: { label: 'Height (cm)' }, weight: { label: 'Weight (kg)', color: 'var(--chart-1)' }, };}Anatomy
A chart (its rows and config), its plot with the series, and the tooltip and legend you write from their state.
import { ScChart, ScChartPlot, ScChartCategoryAxis, ScChartCursor, ScChartGrid, ScChartValueAxis, ScChartScatter, ScChartTooltip, ScChartTooltipIndicator, ScChartTooltipItem, ScChartTooltipName, ScChartTooltipPortal, ScChartTooltipProvider, ScChartTooltipValue } from '@semantic-components/ui/charts';<div scChart [config]="…" [data]="…"> <svg scChartPlot categoryKey="…" aria-label="…"> <g scChartGrid /> <g scChartCategoryAxis /> <g scChartValueAxis /> <g scChartCursor /> <g scChartScatter key="…" xKey="…" /> </svg> <div scChartTooltipProvider> <ng-template scChartTooltipPortal> <div scChartTooltip #tooltip="scChartTooltip"> <div scChartTooltipLabel>…</div> <div scChartTooltipItem [item]="…"> <span scChartTooltipIndicator></span> <span scChartTooltipName>…</span> <span scChartTooltipValue>…</span> </div> </div> </ng-template> </div></div>Accessibility
- The plot is one tab stop, a group named by its aria-label: the arrow keys, Home and End move through its points; Escape closes the tooltip.
- As the keyboard moves, screen readers hear what the tooltip says, through the CDK's LiveAnnouncer (politely).
- Its axes, grid and cursor are hidden from assistive technology: the tooltip says what they show.
- Right to left, it can be mirrored (the app's charts.followDirection, or the axes' reversed): the arrows then go the way it is drawn.
- With reduced motion (prefers-reduced-motion), it appears and changes at once.
Examples
Bubbles
import { DecimalPipe } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import { ScChart, ScChartCategoryAxis, type ScChartConfig, ScChartGrid, ScChartPlot, ScChartScatter, ScChartTooltip,RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScChart, ScChartCategoryAxis, type ScChartConfig, ScChartGrid, ScChartPlot, ScChartScatter, ScChartTooltip,API reference
The series' inputs. The chart, its plot, axes, tooltip and legend are on the Chart page.
| Input | Type | Default | Description |
|---|---|---|---|
key | string (required) | — | each point's y value |
xKey | string (required) | — | each point's x value |
sizeKey | string | '' | a third value, each point's size (area) |
radius | number | 5 | its points' radius — the largest's, with a sizeKey |
fillOpacity | number | 0.7 | |
isAnimationActive | boolean | true | its points grow when it appears (Recharts' entrance) |
animationBegin | number | 0 | the wait before it starts, in ms |
animationDuration | number | 400 | how long it lasts, in ms |
animationEasing | ease, ease-in, ease-out, ease-in-out, linear | linear | |
animationMatchBy | 'index' (by position, stretched), 'append' (the first with the first) or (row, index) => key | 'append' | how its shapes before and after a change are paired (Recharts') |
class | string | '' | Merged over its own classes. |