Dashed Line Styling

Demonstrates how create Angular Charts with dashed lines using SciChart.js, High Performance JavaScript Charts

Fullscreen

Edit

 Edit

Docs

drawExample.ts

angular.ts

ExampleDataProvider.ts

theme.ts

Copy to clipboard
Minimise
Fullscreen
1import { appTheme } from "../../../theme";
2import { ExampleDataProvider } from "../../../ExampleData/ExampleDataProvider";
3
4import {
5    ENumericFormat,
6    FastBandRenderableSeries,
7    FastLineRenderableSeries,
8    FastMountainRenderableSeries,
9    GradientParams,
10    MouseWheelZoomModifier,
11    NumberRange,
12    NumericAxis,
13    Point,
14    SciChartSurface,
15    TSciChart,
16    XyDataSeries,
17    XyyDataSeries,
18    ZoomExtentsModifier,
19    ZoomPanModifier,
20} from "scichart";
21
22// tslint:disable:no-empty
23// tslint:disable:max-classes-per-file
24
25export const drawExample = async (rootElement: string | HTMLDivElement) => {
26    const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
27        theme: appTheme.SciChartJsTheme,
28    });
29
30    // Create XAxis
31    sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { labelFormat: ENumericFormat.Decimal, labelPrecision: 2 }));
32
33    // Create YAxis
34    sciChartSurface.yAxes.add(
35        new NumericAxis(wasmContext, {
36            growBy: new NumberRange(0.1, 0.1),
37        })
38    );
39
40    // Create a Mountain series with a dashed line
41    sciChartSurface.renderableSeries.add(
42        new FastMountainRenderableSeries(wasmContext, {
43            stroke: "SteelBlue",
44            fillLinearGradient: new GradientParams(new Point(0, 0), new Point(0, 1), [
45                { color: appTheme.VividSkyBlue + "77", offset: 0 },
46                { color: "Transparent", offset: 0.5 },
47            ]),
48            strokeThickness: 3,
49            dataSeries: createLineData(wasmContext, 2),
50            // Strokedash array defines the stroke dash. [10,5] means draw for 10pts, gap for 5pts
51            strokeDashArray: [10, 5],
52        })
53    );
54
55    // Create a line series with a dotted line
56    sciChartSurface.renderableSeries.add(
57        new FastLineRenderableSeries(wasmContext, {
58            stroke: appTheme.VividSkyBlue,
59            strokeThickness: 2,
60            dataSeries: createLineData(wasmContext, 1),
61            // Strokedash array defines the stroke dash. [5,5] means draw for 5pts, gap for 5pts
62            strokeDashArray: [5, 5],
63        })
64    );
65
66    // Create a line series a dotted line
67    sciChartSurface.renderableSeries.add(
68        new FastLineRenderableSeries(wasmContext, {
69            stroke: appTheme.VividSkyBlue,
70            strokeThickness: 2,
71            dataSeries: createLineData(wasmContext, 0),
72            // Strokedash array defines the stroke dash. [3,3] means draw for 3pt, gap for 3pt
73            strokeDashArray: [3, 3],
74        })
75    );
76
77    // Create a band series with dashed lines and add to the chart
78    sciChartSurface.renderableSeries.add(
79        new FastBandRenderableSeries(wasmContext, {
80            dataSeries: createBandData(wasmContext),
81            strokeThickness: 2,
82            fill: appTheme.VividSkyBlue + "33",
83            fillY1: appTheme.VividSkyBlue + "33",
84            stroke: appTheme.VividSkyBlue,
85            strokeY1: appTheme.VividSkyBlue,
86            // strokeDashArray: [10, 10],
87            // strokeY1DashArray: [3, 3]
88        })
89    );
90
91    // Add some interactivity modifiers
92    sciChartSurface.chartModifiers.add(new ZoomPanModifier({ enableZoom: true }));
93    sciChartSurface.chartModifiers.add(new MouseWheelZoomModifier());
94    sciChartSurface.chartModifiers.add(new ZoomExtentsModifier());
95
96    sciChartSurface.zoomExtents();
97
98    return { sciChartSurface, wasmContext };
99};
100
101// Creates some dummy data and appends into an XyDataSeries for the example
102const createLineData = (wasmContext: TSciChart, whichSeries: number) => {
103    const data = ExampleDataProvider.getFourierSeriesZoomed(1.0, 0.1, 5.0, 5.15);
104    const xyDataSeries = new XyDataSeries(wasmContext);
105
106    xyDataSeries.appendRange(
107        data.xValues,
108        data.yValues.map((y) => (whichSeries === 0 ? y : whichSeries === 1 ? y * 1.1 : y * 1.5))
109    );
110    return xyDataSeries;
111};
112
113const createBandData = (wasmContext: TSciChart) => {
114    const data0 = ExampleDataProvider.getFourierSeriesZoomed(0.6, 0.13, 5.0, 5.15);
115    const data1 = ExampleDataProvider.getFourierSeriesZoomed(0.5, 0.12, 5.0, 5.15);
116    const xyyDataSeries = new XyyDataSeries(wasmContext);
117    xyyDataSeries.appendRange(data0.xValues, data0.yValues, data1.yValues);
118    return xyyDataSeries;
119};
120

Dashed Line Styling - Angular

Overview

This example demonstrates the integration of SciChart.js within an Angular application to create high-performance 2D charts featuring advanced dashed and dotted line styling. Designed to showcase various styling techniques, the chart includes a mountain series with gradient fills, multiple line series with different dash patterns, and a band series for additional visual context.

Technical Implementation

The chart is initialized asynchronously using SciChartSurface within a standalone Angular component that leverages the ScichartAngularComponent for seamless integration. Numeric axes are configured with custom label formatting and precision, while renderable series are styled using the strokeDashArray property to achieve the desired dashed and dotted effects. Gradient fills are applied to the mountain series using defined gradient parameters. The asynchronous initialization method aligns with best practices as outlined in the Getting Started with SciChart JS documentation.

Features and Capabilities

The example highlights several key features:

  • Advanced Line Styling: Multiple renderable series apply varying dash patterns, including a mountain series with a strokeDashArray: [10,5] dash pattern and line series with strokeDashArray: [5,5] and strokeDashArray: [3,3] dash and dotted patterns.
  • Gradient Styling: The mountain series uses gradient fills to seamlessly blend colors, adding visual depth.
  • Interactive Modifiers: Interactive chart behaviors are enabled via modifiers such as ZoomPanModifier, MouseWheelZoomModifier, and ZoomExtentsModifier, enhancing user interaction and navigation.
  • Optimized Rendering: Leveraging WebGL for high performance, the chart manages real-time interactions and animations efficiently.

Integration and Best Practices

Developers can integrate this example into their Angular projects by using standalone Angular components, ensuring the chart is loaded asynchronously and managed effectively throughout the component lifecycle. Proper resource disposal is advised to prevent memory leaks, as highlighted in the Getting Started with SciChart JS guide. Interactive features can be further customized by referring to the Common ChartModifiers Features documentation, which provides additional context on implementing robust chart interactivity.

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

Using Theme Manager in Angular Chart | SciChart.js Demo

Using Theme Manager in Angular Chart

Demonstrates our Light and Dark Themes for Angular Charts with SciChart.js ThemeManager 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)

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.