Using Theme Manager in Angular Chart

Demonstrates the light and dark theme in SciChart.js, High Performance JavaScript Charts

Fullscreen

Edit

 Edit

Docs

drawExample.ts

index.tsx

ExampleDataProvider.ts

theme.ts

Copy to clipboard
Minimise
Fullscreen
1import {
2    EAnimationType,
3    ECoordinateMode,
4    EHorizontalAnchorPoint,
5    FastLineRenderableSeries,
6    IThemeProvider,
7    NumberRange,
8    NumericAxis,
9    SciChartJSDarkv2Theme,
10    SciChartJSLightTheme,
11    SciChartJsNavyTheme,
12    SciChartSurface,
13    TextAnnotation,
14    XyDataSeries,
15} from "scichart";
16import { ExampleDataProvider } from "../../../ExampleData/ExampleDataProvider";
17
18export const getChartsInitializationAPI = () => {
19    const createLineData = (whichSeries: number) => {
20        const data = ExampleDataProvider.getFourierSeriesZoomed(1.0, 0.1, 5.0, 5.15);
21
22        return {
23            xValues: data.xValues,
24            yValues: data.yValues.map((y) => (whichSeries === 0 ? y : whichSeries === 1 ? y * 1.1 : y * 1.5)),
25        };
26    };
27
28    const createThemedChart = async (rootElement: string | HTMLDivElement, title: string, theme: IThemeProvider) => {
29        // Create a SciChartSurface passing theme into constructor options
30        const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
31            theme,
32        });
33
34        // Create the X,Y Axis
35        sciChartSurface.xAxes.add(
36            new NumericAxis(wasmContext, {
37                labelPrecision: 2,
38                maxAutoTicks: 8,
39            })
40        );
41        sciChartSurface.yAxes.add(
42            new NumericAxis(wasmContext, {
43                labelPrecision: 2,
44                maxAutoTicks: 8,
45                growBy: new NumberRange(0.05, 0.2),
46            })
47        );
48
49        // Add title annotation
50        sciChartSurface.annotations.add(
51            new TextAnnotation({
52                text: title,
53                fontSize: 16,
54                textColor: theme.tickTextBrush,
55                x1: 0.5,
56                y1: 0,
57                opacity: 0.77,
58                horizontalAnchorPoint: EHorizontalAnchorPoint.Center,
59                xCoordinateMode: ECoordinateMode.Relative,
60                yCoordinateMode: ECoordinateMode.Relative,
61            })
62        );
63
64        let data = createLineData(2);
65
66        // Create and add a line series to the chart
67        sciChartSurface.renderableSeries.add(
68            new FastLineRenderableSeries(wasmContext, {
69                dataSeries: new XyDataSeries(wasmContext, { xValues: data.xValues, yValues: data.yValues }),
70                stroke: "auto",
71                strokeThickness: 3,
72                animation: {
73                    type: EAnimationType.Sweep,
74                    options: { duration: 500 },
75                },
76            })
77        );
78
79        data = createLineData(1);
80
81        // Create and add a line series to the chart
82        sciChartSurface.renderableSeries.add(
83            new FastLineRenderableSeries(wasmContext, {
84                dataSeries: new XyDataSeries(wasmContext, { xValues: data.xValues, yValues: data.yValues }),
85                stroke: "auto",
86                strokeThickness: 3,
87                animation: {
88                    type: EAnimationType.Sweep,
89                    options: { duration: 500 },
90                },
91            })
92        );
93
94        data = createLineData(0);
95
96        // Create and add a line series to the chart
97        sciChartSurface.renderableSeries.add(
98            new FastLineRenderableSeries(wasmContext, {
99                dataSeries: new XyDataSeries(wasmContext, { xValues: data.xValues, yValues: data.yValues }),
100                stroke: "auto",
101                strokeThickness: 3,
102                animation: {
103                    type: EAnimationType.Sweep,
104                    options: { duration: 500 },
105                },
106            })
107        );
108
109        return { sciChartSurface };
110    };
111
112    const createNavyThemeChart = (divId: string | HTMLDivElement) =>
113        createThemedChart(divId, "Navy Theme", new SciChartJsNavyTheme());
114    const createLightThemeChart = (divId: string | HTMLDivElement) =>
115        createThemedChart(divId, "Light Theme", new SciChartJSLightTheme());
116    const createDarkThemeChart = (divId: string | HTMLDivElement) =>
117        createThemedChart(divId, "Dark Theme", new SciChartJSDarkv2Theme());
118    const createCustomThemeChart = (divId: string | HTMLDivElement) =>
119        createThemedChart(divId, "Custom Theme", customTheme);
120
121    return { createNavyThemeChart, createLightThemeChart, createDarkThemeChart, createCustomThemeChart };
122};
123
124// Create a custom theme based on light theme + some modifications
125const customTheme: IThemeProvider = {
126    ...new SciChartJSLightTheme(),
127    axisBandsFill: "#83D2F511",
128    axisBorder: "#1F3D68",
129    gridBackgroundBrush: "white",
130    gridBorderBrush: "white",
131    loadingAnimationForeground: "#6495ED77",
132    loadingAnimationBackground: "#E4F5FC",
133    majorGridLineBrush: "#264B9322",
134    minorGridLineBrush: "#264B9306",
135    sciChartBackground: "#E4F5FC",
136    tickTextBrush: "#1F3D68",
137    axisTitleColor: "#1F3D68",
138    // auto / default colour palette for lines and fills
139    strokePalette: ["#264B93", "#A16DAE", "#C52E60"],
140    fillPalette: ["#264B9333", "#A16DAE33", "#C52E6033"],
141};
142

Themeing Angular Charts with SciChart.js

Overview

This Angular example, "Using Theme Manager in Angular Chart", demonstrates how to integrate SciChart.js ThemeManager API within an Angular application to render multiple themed charts. The example showcases four distinct themes – Navy (SciChartJsNavyTheme), Light (SciChartJSLightTheme), and Dark (SciChartJSDarkv2Theme) alongside a customTheme created by merging properties from a built-in theme (see IThemeProvider) – applied to high performance 2D charts that feature animated line series and numeric axes.

Technical Implementation

The implementation leverages asynchronous initialization patterns typically used in Angular. A central API function asynchronously creates a SciChartSurface by configuring numeric axes, adding text annotations, and rendering multiple animated line series using the sweep animation type. Custom theming is achieved by extending the base SciChartJSLightTheme, modifying properties such as axis colors, grid styles, and stroke palettes. This procedure follows the guidelines outlined in the Creating a Custom Theme documentation, and it aligns well with typical asynchronous patterns described in the Getting Started with SciChart JS guide.

Features and Capabilities

The example provides robust theming capabilities by enabling the dynamic application of multiple themes. Each chart is constructed with three animated line series that benefit from the efficient WebGL rendering engine. The responsive layout ensures that the charts adapt to various screen sizes, offering a smooth user experience while maximizing performance as highlighted in the Performance Tips documentation.

Integration and Best Practices

The Angular integration emphasizes proper lifecycle management, including efficient resource cleanup which is essential for maintaining performance in data-rich applications. Developers can refer to the Angular Lifecycle Hooks for guidance on initializing and disposing of components appropriately. The use of asynchronous chart creation functions not only improves performance but also aligns with modern Angular best practices for handling dynamic content. Additionally, the implementation makes use of responsive grid layouts to enhance the user interface, underscoring practical techniques for integrating advanced charting solutions in Angular.

For further details on SciChart.js theming, please see the SciChart.js ThemeManager Documentation.

angular Chart Examples & Demos

See Also: Styling and Theming (11 Demos)

Chart Background Image with Transparency | SciChart.js

Chart Background Image with Transparency

Demonstrates how to create a Angular Chart with background image using transparency in SciChart.js

Styling a Angular Chart in Code | Angular Charts | SciChart.js

Styling a Angular Chart in Code

Demonstrates how to style a Angular Chart entirely in code with SciChart.js themeing API

Create a Custom Theme for Angular Chart | SciChart.js

Create a Custom Theme for Angular Chart

Demonstrates how to create a Custom Theme for a SciChart.js Angular Chart using our Theming API

Coloring Series per-point using the PaletteProvider

Coloring Series per-point using the PaletteProvider

Demonstrates per-point coloring in JavaScript chart types with SciChart.js PaletteProvider API

Angular Point-Markers Chart | Angular Charts | SciChart.js

Angular Point-Markers Chart

Demonstrates the different point-marker types for Angular Scatter charts (Square, Circle, Triangle and Custom image point-marker)

Dashed Line Styling | Angular Charts | SciChart.js Demo

Dashed Line Styling

Demonstrates dashed line series in Angular Charts with SciChart.js

Data Labels | Angular Charts | SciChart.js Demo

Data Labels

Show data labels on Angular Chart. Get your free demo now.

Angular Chart with Multi-Style Series | SciChart.js Demo

Angular Chart with Multi-Style Series

Demonstrates how to apply multiple different styles to a single series using RenderDataTransform

Angular Chart with lines split by thresholds | SciChart

Angular Chart with lines split by thresholds

Demonstrates how to use a RenderDataTransform to split lines into multiple segments so they can be individually colored according to thresholds

Angular Chart Title | Angular Charts | SciChart.js Demo

Angular Chart Title

Demonstrates chart title with different position and alignment options

NEW!
Angular Order of Rendering | Angular Charts | SciChart.js

Angular Order of Rendering Example

The Angular Order of Rendering example gives you full control of the draw order of series and annotations for charts. Try SciChart's advanced customizations.

SciChart Ltd, 16 Beaufort Court, Admirals Way, Docklands, London, E14 9XL.