Bubble chart
Points on two axes, sized by a third value, with names and groups. Good for comparing a few items on three measures at once.
The smallest code that works. change the code, then press Run
In your framework
import { Chart } from 'nervure/react';
const spec = {
type: 'scatter',
xLabel: 'Price',
yLabel: 'Rating',
labels: true,
legend: true,
data: [
{ x: 26, y: 35, radius: 23, label: 'Kairouan', group: 'North' },
{ x: 12, y: 66, radius: 7, label: 'Gabes', group: 'South' },
{ x: 43, y: 37, radius: 11, label: 'Sousse', group: 'East' },
{ x: 68, y: 21, radius: 14, label: 'Mahdia', group: 'North' },
{ x: 57, y: 53, radius: 21, label: 'Djerba', group: 'South' },
{ x: 24, y: 49, radius: 16, label: 'Sfax', group: 'East' },
{ x: 80, y: 36, radius: 16, label: 'Bizerte', group: 'North' },
{ x: 38, y: 24, radius: 20, label: 'Tunis', group: 'South' },
{ x: 32, y: 53, radius: 23, label: 'Nabeul', group: 'East' },
],
};
export default function Example() {
return <Chart spec={spec} style={{ height: 340 }} />;
}Or import this chart alone: what each import weighs.
Options
Beside the fields shared by every chart (title, format, heading, export…), type scatter takes:
interface ScatterSpec extends Base {
type: 'scatter';
data: ScatterPoint[];
/** A colour, or a function `(y, index, label) => colour` (from code only); a point's own `color` wins. */
color?: string | ColorFn;
/** Shape of the points: `circle` by default. The canvas (`render`) always paints circles. */
shape?: PointShape;
xLabel?: string;
yLabel?: string;
/** Names written above the points. */
labels?: boolean;
legend?: boolean | LegendOptions;
lines?: ReferenceLine[];
annotations?: Annotation[];
/** Range, ticks, format and grid of each axis. */
xAxis?: AxisScale;
yAxis?: AxisScale;
/** Axes crossing at zero, inside the drawing, instead of along its edges. */
center?: boolean;
tooltip?: (point: ScatterPoint, format: (v: number) => string) => string[];
onPointClick?: (point: ScatterPoint) => void;
/**
* Points as SVG circles, or painted on one canvas: much faster with tens of thousands of points.
* `auto` (default) uses a canvas above 3000 points, where there is one. Axes, legend and labels stay SVG.
*/
render?: 'svg' | 'canvas' | 'auto';
}
interface ScatterPoint {
x: number;
/** A line across the chart: a target, an average, a date. */
interface ReferenceLine {
value?: number;
/** A note pinned on the chart. `at` is a category (xy) or an x value (scatter). */
interface Annotation {
at: string | number | Date;
/** Range, ticks and grid of a value axis. */
interface AxisScale {
/** `log` ignores zero and negative values. */ scale?: 'linear' | 'log';Style it
- Colours:
theme.palette,chart.setColor(name, colour), or--nervure-palettein your CSS. More - Marks:
[data-series="name"], parts:[data-part="axes"],legend,series. What you change is kept in exports. - Movement:
animation: falsedraws at once. More - Files:
chart.download('png'),svg,csv. More