Skip to main content

The Fan Charts Type

Fan Charts are provided by using multiple Band Series on the same chart.

tip

The JavaScript Fan Chart Example can be found in the SciChart.Js Examples Suite on Github, or our live demo at scichart.com/demo

Above: The JavaScript Fan Chart example from the SciChart.js Demo

Create a Fan Chart

There is no Fan Chart type out of the box in SciChart.js, but it is easy to create one using multiple Band series. Start with the following code:

// Demonstrates how to create a fan chart using SciChart.js
const {
SciChartSurface,
NumericAxis,
FastLineRenderableSeries,
FastBandRenderableSeries,
XyDataSeries,
XyyDataSeries,
SciChartJsNavyTheme
} = SciChart;
// or, for npm, import { SciChartSurface, ... } from "scichart"

const { wasmContext, sciChartSurface } = await SciChartSurface.create(divElementId, {
theme: new SciChartJsNavyTheme()
});
sciChartSurface.xAxes.add(new NumericAxis(wasmContext));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext));

// get data for the fan chart
// format is [{ date, actual, varMax, var4, var3, var2, var1, varMin }]
const varianceData = getVarianceData();
const xValues = varianceData.map(v => v.date);

// Add a line series with the Xy data (the actual data)
sciChartSurface.renderableSeries.add(
new FastLineRenderableSeries(wasmContext, {
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues: varianceData.map(v => v.actual) }),
stroke: "#3388FF"
})
);

// Add band series with progressively higher opacity for the fan variance data
sciChartSurface.renderableSeries.add(
new FastBandRenderableSeries(wasmContext, {
dataSeries: new XyyDataSeries(wasmContext, {
xValues,
yValues: varianceData.map(v => v.varMin),
y1Values: varianceData.map(v => v.varMax)
}),
opacity: 0.15,
fill: "#3388FF",
stroke: "#00000000",
strokeY1: "#00000000"
})
);
sciChartSurface.renderableSeries.add(
new FastBandRenderableSeries(wasmContext, {
dataSeries: new XyyDataSeries(wasmContext, {
xValues,
yValues: varianceData.map(v => v.var1),
y1Values: varianceData.map(v => v.var4)
}),
opacity: 0.33,
fill: "#3388FF",
stroke: "#00000000",
strokeY1: "#00000000"
})
);
sciChartSurface.renderableSeries.add(
new FastBandRenderableSeries(wasmContext, {
dataSeries: new XyyDataSeries(wasmContext, {
xValues,
yValues: varianceData.map(v => v.var2),
y1Values: varianceData.map(v => v.var3)
}),
opacity: 0.5,
fill: "#3388FF",
stroke: "#00000000",
strokeY1: "#00000000"
})
);

This results in the following output:

In the example above: