This example showcases how to create a React Spline Mountain Chart using SciChart.js' feature-rich and High Performance JavaScript Charts.
import { appTheme } from "./appTheme";
import {
EllipsePointMarker,
GradientParams,
MouseWheelZoomModifier,
NumericAxis,
NumberRange,
Point,
RubberBandXyZoomModifier,
SciChartSurface,
SplineMountainRenderableSeries,
WaveAnimation,
XyDataSeries,
ZoomExtentsModifier,
} from "scichart";
export const drawExample = async (rootElement: string | HTMLDivElement) => {
// Create a SciChartSurface
const { wasmContext, sciChartSurface } = await SciChartSurface.create(rootElement, {
theme: appTheme.SciChartJsTheme,
});
// Create an XAxis and YAxis
sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { axisTitle: "X Axis" }));
sciChartSurface.yAxes.add(
new NumericAxis(wasmContext, {
growBy: new NumberRange(0.05, 0.2),
axisTitle: "Y Axis",
})
);
// Create some data to add to the chart
const xValues = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
const yValues = [50, 35, 61, 58, 50, 50, 40, 53, 55, 23, 45, 12, 59, 60];
// Create a Spline Mountain Series and add to the chart
sciChartSurface.renderableSeries.add(
new SplineMountainRenderableSeries(wasmContext, {
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues }),
interpolationPoints: 20, // Sets number of points to interpolate to smooth the line
stroke: appTheme.VividSkyBlue,
strokeThickness: 5,
zeroLineY: 0.0,
fill: appTheme.VividSkyBlue, // when a solid color is required, use fill
// when a gradient is required, use fillLinearGradient
fillLinearGradient: new GradientParams(new Point(0, 0), new Point(0, 1), [
{ color: appTheme.MutedSkyBlue, offset: 0 },
{ color: "Transparent", offset: 1 },
]),
pointMarker: new EllipsePointMarker(wasmContext, {
strokeThickness: 3,
width: 13,
height: 13,
stroke: appTheme.VividSkyBlue,
fill: appTheme.ForegroundColor,
}),
animation: new WaveAnimation({ duration: 1000, fadeEffect: true, zeroLine: 10 }),
})
);
// Optional: Add some interactivity to the chart
sciChartSurface.chartModifiers.add(
new ZoomExtentsModifier(),
new RubberBandXyZoomModifier(),
new MouseWheelZoomModifier()
);
sciChartSurface.zoomExtents();
return { wasmContext, sciChartSurface };
};
This React example demonstrates how to integrate SciChart.js high-performance charts into a React application using the <SciChartReact/> component. It showcases the creation of a smooth and visually appealing spline mountain chart with gradient fills and animated transitions, leveraging asynchronous initialization and WebAssembly for optimal performance.
The chart is initialized asynchronously via an async function that creates a SciChartSurface and adds NumericAxis. A SplineMountainRenderableSeries is constructed with 20 interpolation points to achieve smoothness, along with gradient fills defined using linear gradient parameters. Interactive modifiers such as ZoomExtentsModifier, RubberBandXyZoomModifier, and MouseWheelZoomModifier are added to improve user experience. This approach follows best practices for React integration and utilizes WebAssembly for enhanced performance as outlined in the Performance Tips & Tricks documentation.
The example features real-time rendering of the spline mountain series with advanced customization capabilities. It illustrates the use of gradient fills for a more dynamic visual style and employs a WaveAnimation effect to add life to the chart. The configuration in the example provides detailed control over the series properties—including stroke settings, point markers, and animation parameters—demonstrating the flexibility offered by SciChart.js. For additional details on the series configuration, see The Spline (Smoothed) Mountain Series Type documentation.
Integration within React is achieved by encapsulating the chart initialization inside a functional component via the <SciChartReact/> wrapper. This not only simplifies the management of asynchronous initialization but also aligns with modern React practices. Developers are encouraged to ensure proper resource cleanup to prevent memory leaks, a concept covered in various performance optimization articles. Moreover, interactive modifiers integrated into the example empower users with zooming and panning capabilities, showcasing the adaptability of SciChart.js in a React environment. For further guidance, refer to the Creating a SciChart React Component from the Ground Up resource.








































