Scatter and bubble chart
Points on two axes, with a size and a group. Good for the link between two measures.
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: 'Sales',
legend: true,
data: [
{ x: 51, y: 27, r: 60, label: 'Item 1', group: 'North' },
{ x: 46, y: 13, r: 56, label: 'Item 2', group: 'South' },
{ x: 49, y: 79, r: 96, label: 'Item 3', group: 'East' },
{ x: 57, y: 79, r: 43, label: 'Item 4', group: 'North' },
{ x: 11, y: 31, r: 20, label: 'Item 5', group: 'South' },
{ x: 9, y: 96, r: 59, label: 'Item 6', group: 'East' },
{ x: 27, y: 13, r: 24, label: 'Item 7', group: 'North' },
{ x: 8, y: 32, r: 2, label: 'Item 8', group: 'South' },
{ x: 41, y: 62, r: 61, label: 'Item 9', group: 'East' },
{ x: 12, y: 97, r: 74, label: 'Item 10', group: 'North' },
{ x: 36, y: 56, r: 93, label: 'Item 11', group: 'South' },
{ x: 47, y: 26, r: 80, label: 'Item 12', group: 'East' },
{ x: 33, y: 55, r: 72, label: 'Item 13', group: 'North' },
{ x: 38, y: 49, r: 15, label: 'Item 14', group: 'South' },
{ x: 59, y: 48, r: 71, label: 'Item 15', group: 'East' },
{ x: 7, y: 73, r: 67, label: 'Item 16', group: 'North' },
{ x: 8, y: 12, r: 63, label: 'Item 17', group: 'South' },
{ x: 40, y: 46, r: 33, label: 'Item 18', group: 'East' },
{ x: 57, y: 66, r: 47, label: 'Item 19', group: 'North' },
{ x: 19, y: 57, r: 39, label: 'Item 20', group: 'South' },
{ x: 41, y: 41, r: 74, label: 'Item 21', group: 'East' },
{ x: 53, y: 19, r: 23, label: 'Item 22', group: 'North' },
{ x: 27, y: 12, r: 75, label: 'Item 23', group: 'South' },
{ x: 59, y: 26, r: 100, label: 'Item 24', group: 'East' },
{ x: 58, y: 30, r: 57, label: 'Item 25', group: 'North' },
{ x: 18, y: 46, r: 38, label: 'Item 26', group: 'South' },
{ x: 14, y: 21, r: 42, label: 'Item 27', group: 'East' },
{ x: 34, y: 42, r: 79, label: 'Item 28', group: 'North' },
{ x: 36, y: 53, r: 71, label: 'Item 29', group: 'South' },
{ x: 34, y: 97, r: 58, label: 'Item 30', group: 'East' },
{ x: 39, y: 59, r: 70, label: 'Item 31', group: 'North' },
{ x: 15, y: 24, r: 3, label: 'Item 32', group: 'South' },
{ x: 18, y: 31, r: 57, label: 'Item 33', group: 'East' },
{ x: 57, y: 48, r: 95, label: 'Item 34', group: 'North' },
{ x: 37, y: 89, r: 7, label: 'Item 35', group: 'South' },
{ x: 24, y: 66, r: 71, label: 'Item 36', group: 'East' },
{ x: 61, y: 52, r: 36, label: 'Item 37', group: 'North' },
{ x: 35, y: 85, r: 87, label: 'Item 38', group: 'South' },
{ x: 47, y: 70, r: 26, label: 'Item 39', group: 'East' },
{ x: 63, y: 97, r: 15, label: 'Item 40', group: 'North' },
{ x: 44, y: 32, r: 43, label: 'Item 41', group: 'South' },
{ x: 38, y: 11, r: 6, label: 'Item 42', 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[];
color?: string;
xLabel?: string;
yLabel?: string;
/** Names written above the points. */
labels?: boolean;
legend?: boolean;
lines?: ReferenceLine[];
annotations?: Annotation[];
tooltip?: (point: ScatterPoint, format: (v: number) => string) => string[];
onPointClick?: (point: ScatterPoint) => void;
}
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;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