Draw JavaScript Chart Behind Axis

Demonstrates how to create a JavaScript Chart with transparent axes using SciChart.js, High Performance JavaScript Charts

Fullscreen

Edit

 Edit

Docs

drawExample.ts

index.tsx

theme.ts

Copy to clipboard
Minimise
Fullscreen
1import {
2    ECoordinateMode,
3    EHorizontalAnchorPoint,
4    ELineDrawMode,
5    FastLineRenderableSeries,
6    MouseWheelZoomModifier,
7    NumberRange,
8    NumericAxis,
9    PinchZoomModifier,
10    SciChartSurface,
11    TextAnnotation,
12    XyDataSeries,
13    ZoomPanModifier,
14    Thickness,
15} from "scichart";
16import { appTheme } from "../../../theme";
17
18export const drawExample = async (rootElement: string | HTMLDivElement) => {
19    const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
20        theme: appTheme.SciChartJsTheme,
21        title: "SciChartSurface with Series Drawn Behind Axis",
22        titleStyle: {
23            fontSize: 20,
24            fontWeight: "Bold",
25            placeWithinChart: true,
26            padding: Thickness.fromString("14 2 10 0"),
27            color: appTheme.ForegroundColor + "C4",
28        },
29    });
30
31    // When true, Series are drawn behind axis (Axis inside chart)
32    sciChartSurface.drawSeriesBehindAxis = true;
33
34    sciChartSurface.xAxes.add(
35        new NumericAxis(wasmContext, {
36            growBy: new NumberRange(0.1, 0.1),
37            visibleRange: new NumberRange(28.0, 42.6),
38            axisTitle: "X Axis",
39            labelStyle: {
40                fontSize: 20,
41            },
42            axisBorder: {
43                borderTop: 0,
44                color: appTheme.PaleSkyBlue + "33",
45            },
46        })
47    );
48    sciChartSurface.yAxes.add(
49        new NumericAxis(wasmContext, {
50            growBy: new NumberRange(0.1, 0.1),
51            visibleRange: new NumberRange(-40.0, 140.0),
52            axisTitle: "Y Axis",
53            labelStyle: {
54                fontSize: 20,
55            },
56            axisBorder: {
57                borderLeft: 0,
58                color: appTheme.PaleSkyBlue + "33",
59            },
60        })
61    );
62
63    const xValues = [];
64    const yValues = [];
65    const y1Values = [];
66
67    for (let i = 0; i < 100; i += 0.1) {
68        xValues.push(i);
69        yValues.push(Math.tan(i));
70        y1Values.push(Math.cos(i * 100) * 5);
71    }
72
73    sciChartSurface.renderableSeries.add(
74        new FastLineRenderableSeries(wasmContext, {
75            drawNaNAs: ELineDrawMode.PolyLine,
76            strokeThickness: 5,
77            stroke: "rgba(255, 134, 72, .47)",
78            dataSeries: new XyDataSeries(wasmContext, { xValues, yValues }),
79        })
80    );
81
82    sciChartSurface.renderableSeries.add(
83        new FastLineRenderableSeries(wasmContext, {
84            drawNaNAs: ELineDrawMode.PolyLine,
85            strokeThickness: 3,
86            stroke: "rgba(50, 134, 72, .47)",
87            dataSeries: new XyDataSeries(wasmContext, { xValues, yValues: y1Values }),
88        })
89    );
90
91    sciChartSurface.chartModifiers.add(new ZoomPanModifier({ enableZoom: true }), new MouseWheelZoomModifier());
92
93    return { sciChartSurface, wasmContext };
94};
95

Draw Chart Behind Axes in JavaScript

Overview

This example demonstrates how to create a high performance chart with series rendered behind the axes using SciChart.js in a JavaScript environment. By setting the drawSeriesBehindAxis property to true, the chart achieves a unique transparent axis effect that enhances visual clarity and differentiates the data series from the axes.

Technical Implementation

The chart is initialized asynchronously using SciChartSurface.create() as explained in the Getting Started with SciChart JS guide. In the drawExample function, a SciChartSurface is configured with a custom theme, titleStyle, and essential properties such as drawSeriesBehindAxis to display the series behind the numeric axes. The NumericAxis themselves are configured with properties like visibleRange, growBy, and custom axisBorder settings as detailed in the NumericAxis Styling documentation. Two FastLineRenderableSeries are added to the chart using XyDataSeries. Additionally, interactive modifiers such as ZoomPanModifier and MouseWheelZoomModifier are included to enable dynamic zooming and panning capabilities as illustrated in the Tutorial 03 - Adding Zooming, Panning Behavior guide.

Features and Capabilities

The core feature of this example is the dynamic rendering customization controlled by the drawSeriesBehindAxis property, which allows series to be drawn either behind the axes for enhanced visual layering or clipped at the viewport edge. This technique provides both aesthetic appeal and functional clarity when interpreting data trends. The implementation also demonstrates efficient data handling through the use of XyDataSeries and ensures interactivity with built-in WebGL based zoom and pan functionality, taking advantage of SciChart.js performance optimizations as outlined in the Performance Tips & Tricks | JavaScript Chart Documentation.

Integration and Best Practices

By leveraging a standalone JavaScript implementation, the example illustrates how to maintain clear separation of concerns in chart initialization, axis configuration, and series rendering. This approach enables developers to easily integrate SciChart.js into existing JavaScript projects without reliance on additional frameworks or hooks. For further customization and to ensure optimal rendering performance, developers are encouraged to review the relevant documentation links provided above, which offer both conceptual and practical guidance on configuring SciChartSurface options, styling, and interactive behavior.

javascript Chart Examples & Demos

See Also: Chart Axis APIs (11 Demos)

JavaScript Chart with Multiple X Axes | SciChart.js Demo

JavaScript Chart with Multiple X Axes

Demonstrates Multiple X & Y Axis on a JavaScript Chart using SciChart.js. SciChart supports unlimited left, right, top, bottom X, Y axis with configurable alignment and individual zooming, panning

JavaScript Chart with Secondary Y Axes | SciChart.js Demo

JavaScript Chart with Secondary Y Axes

Demonstrates Secondary Y Axis on a JavaScript Chart using SciChart.js. SciChart supports unlimited, multiple left, right, top, bottom X, Y axis with configurable alignment and individual zooming, panning

JavaScript Vertical Charts | Javascript Charts | SciChart.js

JavaScript Vertical Charts

Demonstrates alignment of Axis to create a vertical chart with SciChart.js - JavaScript Charts.

JavaScript Chart with Central Axes | SciChart.js Demo

JavaScript Chart with Central Axes

Demonstrates Central Axes on a JavaScript Chart using SciChart.js. SciChart supports unlimited left, right, top, bottom X, Y axis with configurable layout

JavaScript Chart with Static X Axis | SciChart.js Demo

JavaScript Chart with Static X Axis

Demonstrates isStaticAxis on a JavaScript Chart using SciChart.js.

JavaScript Chart with Vertically Stacked Axes | SciChart

JavaScript Chart with Vertically Stacked Axes

Demonstrates Vertically Stacked Axes on a JavaScript Chart using SciChart.js, allowing data to overlap

JavaScript Chart with Logarithmic Axis Example | SciChart

JavaScript Chart with Logarithmic Axis Example

Demonstrates Logarithmic Axis on a JavaScript Chart using SciChart.js. SciChart supports logarithmic axis with scientific or engineering notation and positive and negative values

NEW!
JavaScript Chart with DiscontinuousDateAxis Comparison

DiscontinuousDateAxis Comparison with Javascript

NEW!
JavaScript Chart with BaseValue Axes | SciChart.js Demo

JavaScript Chart with BaseValue Axes

Demonstrates BaseValue Axes on a JavaScript Chart using SciChart.js to create non-linear and custom-scaled axes such as log-like scales

Axis Types | Javascript Charts | SciChart.js Demo

Axis Types

Demonstrates how to use arbitrary text for axis labels, rather than formatted data values, using the new TextLabelProvider

JavaScript Chart Axis Layout Options | SciChart.js Demo

JavaScript Chart Axis Layout Options

Demonstrates outer, inner, central and stacked axes, and use of axis alignment to create vertical charts

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