Demonstrates how to style or theme a Angular Chart using SciChart.js, High Performance JavaScript Charts
drawExample.ts
angular.ts
1import {
2 SciChartSurface,
3 NumericAxis,
4 MouseWheelZoomModifier,
5 EAxisAlignment,
6 ZoomPanModifier,
7 TextAnnotation,
8 EHorizontalAnchorPoint,
9 ECoordinateMode,
10} from "scichart";
11
12export const drawExample = async (rootElement: string | HTMLDivElement) => {
13 // Demonstrates how to colour chart parts in code
14 // This is better done by themes, where you can also style the loader pre-scichart initialisation
15 //
16 const chartBackgroundColor = "#E4F5FC";
17 const axisBandsFill = "#1F3D6805";
18 const axisTitleColor = "#1F3D68";
19 const majorGridLineColor = "#264B9355";
20 const minorGridLineColor = "#264B9322";
21 const axisLabelColor = "#1F3D68";
22 const axisBackgroundFill = "#00000000";
23 const borderColor = "#1F3D68";
24
25 const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement);
26 sciChartSurface.background = chartBackgroundColor;
27
28 // Create and style xAxis
29 sciChartSurface.xAxes.add(
30 new NumericAxis(wasmContext, {
31 axisTitle: "X Axis",
32 drawMajorBands: true,
33 axisBandsFill,
34 axisTitleStyle: {
35 fontSize: 25,
36 fontFamily: "Montserrat",
37 fontWeight: "bold",
38 fontStyle: "italic",
39 color: axisTitleColor,
40 },
41 majorGridLineStyle: {
42 strokeThickness: 1,
43 color: majorGridLineColor,
44 strokeDashArray: [10, 5],
45 },
46 minorGridLineStyle: {
47 strokeThickness: 1,
48 color: minorGridLineColor,
49 strokeDashArray: [2, 2],
50 },
51 majorTickLineStyle: {
52 strokeThickness: 1,
53 color: majorGridLineColor,
54 tickSize: 8,
55 },
56 minorTickLineStyle: {
57 strokeThickness: 1,
58 color: minorGridLineColor,
59 tickSize: 4,
60 },
61 useNativeText: false, // this must be false to use labelStyle fontWeight and fontStyle
62 labelStyle: {
63 fontSize: 16,
64 fontWeight: "bold",
65 fontStyle: "Italic",
66 color: axisLabelColor,
67 fontFamily: "Arial",
68 },
69 backgroundColor: axisBackgroundFill,
70 axisBorder: {
71 borderTop: 1,
72 color: borderColor,
73 },
74 })
75 );
76
77 // Create and style left YAxis
78 sciChartSurface.yAxes.add(
79 new NumericAxis(wasmContext, {
80 axisAlignment: EAxisAlignment.Left,
81 axisBandsFill,
82 axisTitle: "Left Y Axis",
83 axisTitleStyle: {
84 fontSize: 25,
85 fontFamily: "Montserrat",
86 fontWeight: "bold",
87 fontStyle: "italic",
88 color: axisTitleColor,
89 },
90 majorGridLineStyle: {
91 strokeThickness: 1,
92 color: majorGridLineColor,
93 strokeDashArray: [10, 5],
94 },
95 minorGridLineStyle: {
96 strokeThickness: 1,
97 color: minorGridLineColor,
98 strokeDashArray: [2, 2],
99 },
100 majorTickLineStyle: {
101 strokeThickness: 1,
102 color: majorGridLineColor,
103 tickSize: 8,
104 },
105 minorTickLineStyle: {
106 strokeThickness: 1,
107 color: minorGridLineColor,
108 tickSize: 4,
109 },
110 useNativeText: false, // this must be false to use labelStyle fontWeight and fontStyle
111 labelStyle: {
112 fontSize: 16,
113 fontWeight: "bold",
114 fontStyle: "Italic",
115 color: axisLabelColor,
116 fontFamily: "Arial",
117 },
118 backgroundColor: axisBackgroundFill,
119 axisBorder: {
120 borderRight: 1,
121 color: borderColor,
122 },
123 })
124 );
125
126 // Create and style right YAxis
127 sciChartSurface.yAxes.add(
128 new NumericAxis(wasmContext, {
129 useNativeText: false,
130 axisTitle: "Right Y Axis",
131 axisTitleStyle: {
132 fontSize: 25,
133 fontFamily: "Montserrat",
134 fontWeight: "bold",
135 fontStyle: "italic",
136 color: axisTitleColor,
137 },
138 axisAlignment: EAxisAlignment.Right,
139 majorGridLineStyle: {
140 strokeThickness: 1,
141 color: majorGridLineColor,
142 strokeDashArray: [10, 5],
143 },
144 minorGridLineStyle: {
145 strokeThickness: 1,
146 color: minorGridLineColor,
147 strokeDashArray: [2, 2],
148 },
149 majorTickLineStyle: {
150 strokeThickness: 1,
151 color: majorGridLineColor,
152 tickSize: 8,
153 },
154 minorTickLineStyle: {
155 strokeThickness: 1,
156 color: minorGridLineColor,
157 tickSize: 4,
158 },
159 labelStyle: {
160 fontSize: 16,
161 fontWeight: "bold",
162 fontStyle: "Italic",
163 color: axisLabelColor,
164 fontFamily: "Arial",
165 },
166 backgroundColor: axisBackgroundFill,
167 axisBorder: {
168 borderLeft: 1,
169 color: borderColor,
170 },
171 })
172 );
173
174 // Add title annotation
175 sciChartSurface.annotations.add(
176 new TextAnnotation({
177 text: "Chart with custom style applied in code",
178 fontSize: 20,
179 fontWeight: "Bold",
180 textColor: axisLabelColor,
181 x1: 0.5,
182 y1: 0,
183 opacity: 0.77,
184 horizontalAnchorPoint: EHorizontalAnchorPoint.Center,
185 xCoordinateMode: ECoordinateMode.Relative,
186 yCoordinateMode: ECoordinateMode.Relative,
187 })
188 );
189
190 // Add some interactivity modifiers
191 sciChartSurface.chartModifiers.add(new ZoomPanModifier({ enableZoom: true }));
192 sciChartSurface.chartModifiers.add(new MouseWheelZoomModifier());
193
194 sciChartSurface.zoomExtents();
195
196 return { sciChartSurface, wasmContext };
197};
198This example demonstrates how to style and theme a SciChart.js chart entirely in code within an Angular application. The code programmatically customizes various chart elements such as the chart background via sciChartSurface.background, NumericAxis properties (including axisTitleStyle, major/minorGridLinesStyle, major/minorTickLinesStyle, labelStyle, backgroundColor and axisBorder.
The chart is integrated using an Angular standalone component with the scichart-angular package. The initialization is performed asynchronously by calling SciChartSurface.create(), which leverages WebAssembly for optimal performance. The example configures NumericAxis with custom styles such as title fonts, grid line dash styles, and tick marks, and it adds interactive modifiers like ZoomPanModifier and MouseWheelZoomModifier to enhance user interactivity.
The example illustrates advanced customizations including detailed styling for both X and Y axes, complete with bespoke title styles, axis bands, and grid line definitions. A text annotation serves as a chart title, demonstrating how annotations can be styled directly in code. Interactive features allow users to pan and zoom, highlighting the flexibility and high performance of SciChart.js in handling real-time chart modifications.
Utilizing the ScichartAngularComponent from scichart-angular, this example provides a modular approach to chart integration that ensures maintainability and performance. By managing chart initialization asynchronously and applying in-code styling, developers can achieve a clear separation of concerns while optimizing rendering performance. For additional insights on in-code chart theming, consult the Chart Styling - Creating a Custom Theme documentation.

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

Demonstrates our Light and Dark Themes for Angular Charts with SciChart.js ThemeManager API

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

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

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

Demonstrates dashed line series in Angular Charts with SciChart.js

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

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

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

Demonstrates chart title with different position and alignment options

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.