Regression line
Points with the line that fits them best, its band of confidence and R². Good for showing how much one measure follows another.
The smallest code that works. change the code, then press Run
In your framework
import { Chart } from 'nervure/react';
const spec = {
type: 'regression',
xLabel: 'Hours of study',
yLabel: 'Score',
data: [
{ x: 51, y: 45, label: 'Student 1' },
{ x: 41, y: 39, label: 'Student 2' },
{ x: 23, y: 44, label: 'Student 3' },
{ x: 48, y: 55, label: 'Student 4' },
{ x: 20, y: 41, label: 'Student 5' },
{ x: 19, y: 41, label: 'Student 6' },
{ x: 59, y: 59, label: 'Student 7' },
{ x: 53, y: 46, label: 'Student 8' },
{ x: 27, y: 51, label: 'Student 9' },
{ x: 29, y: 35, label: 'Student 10' },
{ x: 26, y: 31, label: 'Student 11' },
{ x: 26, y: 25, label: 'Student 12' },
{ x: 86, y: 66, label: 'Student 13' },
{ x: 12, y: 34, label: 'Student 14' },
{ x: 60, y: 59, label: 'Student 15' },
{ x: 10, y: 19, label: 'Student 16' },
{ x: 43, y: 41, label: 'Student 17' },
{ x: 28, y: 52, label: 'Student 18' },
{ x: 30, y: 44, label: 'Student 19' },
{ x: 68, y: 79, label: 'Student 20' },
{ x: 11, y: 38, label: 'Student 21' },
{ x: 44, y: 35, label: 'Student 22' },
{ x: 57, y: 58, label: 'Student 23' },
{ x: 45, y: 49, label: 'Student 24' },
{ x: 76, y: 57, label: 'Student 25' },
{ x: 24, y: 36, label: 'Student 26' },
{ x: 41, y: 52, label: 'Student 27' },
{ x: 52, y: 59, label: 'Student 28' },
{ x: 80, y: 86, label: 'Student 29' },
{ x: 27, y: 37, label: 'Student 30' },
{ x: 54, y: 47, label: 'Student 31' },
{ x: 38, y: 41, label: 'Student 32' },
{ x: 14, y: 19, label: 'Student 33' },
{ x: 70, y: 82, label: 'Student 34' },
{ x: 32, y: 35, label: 'Student 35' },
{ x: 45, y: 53, label: 'Student 36' },
{ x: 86, y: 75, label: 'Student 37' },
{ x: 79, y: 82, label: 'Student 38' },
{ x: 37, y: 40, label: 'Student 39' },
{ x: 21, y: 32, label: 'Student 40' },
],
};
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 regression takes:
interface RegressionSpec extends Base, Axes {
type: 'regression';
data: { x: number; y: number; label?: string }[];
/** 1: a straight line (default); 2: a parabola. */ degree?: 1 | 2;
/** Confidence of the band around the line, 0.95 by default; false hides it. */ band?: number | false;
color?: string;
}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