Fan chart
A history, then a forecast whose bands widen with time. Good for forecasts of sales, prices or rates, with how sure they are.
The smallest code that works. change the code, then press Run
In your framework
import { Chart } from 'nervure/react';
const spec = {
type: 'fan',
labels: [
'Jan 24', 'Feb 24', 'Mar 24', 'Apr 24', 'May 24', 'Jun 24', 'Jul 24', 'Aug 24', 'Sep 24',
'Oct 24', 'Nov 24', 'Dec 24', 'Jan 25', 'Feb 25', 'Mar 25', 'Apr 25', 'May 25', 'Jun 25',
'Jul 25', 'Aug 25', 'Sep 25', 'Oct 25', 'Nov 25', 'Dec 25', 'Jan 26', 'Feb 26', 'Mar 26',
'Apr 26', 'May 26', 'Jun 26', 'Jul 26', 'Aug 26', 'Sep 26', 'Oct 26', 'Nov 26', 'Dec 26',
'Jan 27', 'Feb 27', 'Mar 27', 'Apr 27', 'May 27', 'Jun 27',
],
history: [
100.5, 99.9, 97.5, 97.7, 94.9, 92.2, 93.4, 94, 92, 90.2, 88.1, 86, 90, 86.5, 87.8, 84.1,
83.7, 81.9, 80.2, 82.3, 78.8, 78.5, 79.5, 79.3, 82.3, 80.1, 79.4, 80, 83.3, 81.3,
],
forecast: [
{ value: 81.9, ranges: [[79.9, 83.9], [78.1, 85.7], [76, 87.8]] },
{ value: 82.5, ranges: [[79.7, 85.3], [77.1, 87.9], [74.2, 90.8]] },
{ value: 83.1, ranges: [[79.6, 86.6], [76.4, 89.8], [72.9, 93.3]] },
{ value: 83.7, ranges: [[79.7, 87.7], [76, 91.4], [71.9, 95.5]] },
{ value: 84.3, ranges: [[79.8, 88.8], [75.7, 92.9], [71.2, 97.4]] },
{ value: 84.9, ranges: [[80, 89.8], [75.5, 94.3], [70.5, 99.3]] },
{ value: 85.5, ranges: [[80.2, 90.8], [75.3, 95.7], [69.9, 101.1]] },
{ value: 86.1, ranges: [[80.4, 91.8], [75.2, 97], [69.5, 102.7]] },
{ value: 86.7, ranges: [[80.7, 92.7], [75.2, 98.2], [69.1, 104.3]] },
{ value: 87.3, ranges: [[80.9, 93.7], [75.2, 99.4], [68.7, 105.9]] },
{ value: 87.9, ranges: [[81.2, 94.6], [75.2, 100.6], [68.4, 107.4]] },
{ value: 88.5, ranges: [[81.5, 95.5], [75.2, 101.8], [68.1, 108.9]] },
],
};
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 fan takes:
interface FanSpec extends Base {
type: 'fan';
/** Names of the periods, history then forecast. */ labels?: string[];
history: number[];
/** Each forecast period: the central value and its ranges, from the narrowest to the widest. */
forecast: { value: number; ranges: [number, number][] }[];
/** Confidence of each range in %, 50, 80 and 95 by default. */ levels?: number[];
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