Demonstrates how to create a React Digital Line Chart using SciChart.js, our powerful JavaScript Charts
import {
EllipsePointMarker,
FastLineRenderableSeries,
MouseWheelZoomModifier,
NumberRange,
NumericAxis,
ScaleAnimation,
SciChartSurface,
XyDataSeries,
ZoomExtentsModifier,
ZoomPanModifier,
} from "scichart";
import { RandomWalkGenerator } from "./RandomWalkGenerator";
import { appTheme } from "./appTheme";
export const drawExample = async (rootElement: string | HTMLDivElement) => {
// Create a SciChartSurface
const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
theme: appTheme.SciChartJsTheme,
});
// Create the X,Y Axis
sciChartSurface.xAxes.add(new NumericAxis(wasmContext));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { growBy: new NumberRange(0.05, 0.05) }));
// Create some xValues, yValues arrays
const { xValues, yValues } = new RandomWalkGenerator().Seed(1337).getRandomWalkSeries(25);
// Create and add a line series to the chart
sciChartSurface.renderableSeries.add(
new FastLineRenderableSeries(wasmContext, {
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues }),
stroke: appTheme.VividPink,
strokeThickness: 3,
// Flag isDigitalLine turns a normal line series into a digital line series
isDigitalLine: true,
pointMarker: new EllipsePointMarker(wasmContext, {
width: 11,
height: 11,
fill: appTheme.VividPink,
stroke: appTheme.PaleSkyBlue,
strokeThickness: 2,
}),
animation: new ScaleAnimation({ zeroLine: -1, duration: 500, fadeEffect: true }),
})
);
// OPTIONAL: Add some interactivity modifiers
sciChartSurface.chartModifiers.add(new ZoomPanModifier({ enableZoom: true }));
sciChartSurface.chartModifiers.add(new ZoomExtentsModifier());
sciChartSurface.chartModifiers.add(new MouseWheelZoomModifier());
// Zoom to fit
sciChartSurface.zoomExtents();
return { sciChartSurface, wasmContext };
};
This example demonstrates how to create a digital line chart using SciChart.js within a React framework. It showcases how to configure SciChart surfaces, axes, and a digital line renderable series with animations and interactive modifiers for zooming and panning.
The chart is initialized within an asynchronous function called drawExample that sets up a SciChartSurface and WebAssembly context. The function creates numeric X and Y axes and plots data generated from a custom RandomWalkGenerator. The digital line is implemented by setting the flag isDigitalLine to true on the renderable series, and it includes a custom point marker and a scale animation effect. Developers interested in the architectural details can refer to Creating a SciChart React Component from the Ground Up for in-depth insights.
This example highlights advanced chart features such as advanced series customization with digital line styling, efficient animations using ScaleAnimation, and interactive capabilities with modifiers including ZoomPanModifier, ZoomExtentsModifier, and MouseWheelZoomModifier. These features ensure an engaging user experience and are discussed in the React Digital Line Chart Demo documentation.
The integration is streamlined through the use of the <SciChartReact/> component which accepts an initChart prop pointing to the drawExample function. This approach simplifies embedding SciChart.js into React applications while ensuring optimal performance by leveraging WebAssembly for rendering. Best practices for React integration are further detailed in React Charts with SciChart.js: Introducing "SciChart React" and the efficient use of WebAssembly is elaborated in the Memory Best Practices guide.








































