JavaScript Chart with Logarithmic Axis Example

Demonstrates how to create a JavaScript Chart with Logarithmic axis using 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    ENumericFormat,
3    EllipsePointMarker,
4    FastLineRenderableSeries,
5    LegendModifier,
6    LogarithmicAxis,
7    MouseWheelZoomModifier,
8    NumericAxis,
9    RubberBandXyZoomModifier,
10    SciChartSurface,
11    SweepAnimation,
12    XyDataSeries,
13    Thickness,
14    ZoomExtentsModifier,
15} from "scichart";
16import { appTheme } from "../../../theme";
17import { ExampleDataProvider } from "../../../ExampleData/ExampleDataProvider";
18
19const Y_AXIS_LINEAR_ID = "Y_AXIS_LINEAR_ID";
20const X_AXIS_LINEAR_ID = "X_AXIS_LINEAR_ID";
21
22export const drawExample = async (rootElement: string | HTMLDivElement) => {
23    // Create a SciChartSurface
24    const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
25        theme: {
26            ...appTheme.SciChartJsTheme,
27            majorGridLineBrush: appTheme.MutedSkyBlue + "55",
28            minorGridLineBrush: appTheme.MutedSkyBlue + "22",
29        },
30        title: "Logarithmic X & Y Axis",
31        titleStyle: {
32            fontSize: 20,
33            fontWeight: "bold",
34            placeWithinChart: true,
35            color: appTheme.ForegroundColor + "C4",
36            padding: Thickness.fromString("10 0 4 0"),
37        },
38    });
39
40    // Create an X and Y Axis
41    const xAxisLogarithmic = new LogarithmicAxis(wasmContext, {
42        logBase: 10,
43        labelFormat: ENumericFormat.Scientific,
44        labelPrecision: 2,
45        minorsPerMajor: 10,
46        useNativeText: false,
47    });
48    sciChartSurface.xAxes.add(xAxisLogarithmic);
49
50    // The LogarithmicAxis will apply logarithmic scaling and labelling to your data.
51    // Simply replace a NumericAxis for a LogarithmicAxis on X or Y to apply this scaling
52    // Note options logBase, labelFormat which lets you specify exponent on labels
53    const yAxisLogarithmic = new LogarithmicAxis(wasmContext, {
54        logBase: 10,
55        labelFormat: ENumericFormat.Scientific,
56        labelPrecision: 2,
57        minorsPerMajor: 10,
58        useNativeText: false,
59    });
60    sciChartSurface.yAxes.add(yAxisLogarithmic);
61
62    const xAxisLinear = new NumericAxis(wasmContext, {
63        labelFormat: ENumericFormat.Decimal,
64        labelPrecision: 2,
65        isVisible: false,
66        id: X_AXIS_LINEAR_ID,
67    });
68    sciChartSurface.xAxes.add(xAxisLinear);
69
70    const yAxisLinear = new NumericAxis(wasmContext, {
71        labelFormat: ENumericFormat.Decimal,
72        labelPrecision: 2,
73        isVisible: false,
74        id: Y_AXIS_LINEAR_ID,
75    });
76    sciChartSurface.yAxes.add(yAxisLinear);
77
78    // Create some data
79    const data0 = ExampleDataProvider.getExponentialCurve(2, 100);
80    const data1 = ExampleDataProvider.getExponentialCurve(2.2, 100);
81    const data2 = ExampleDataProvider.getExponentialCurve(2.4, 100);
82
83    sciChartSurface.renderableSeries.add(
84        new FastLineRenderableSeries(wasmContext, {
85            dataSeries: new XyDataSeries(wasmContext, {
86                xValues: data0.xValues,
87                yValues: data0.yValues,
88                dataSeriesName: "y = x ^ 2",
89            }),
90            stroke: appTheme.VividSkyBlue,
91            strokeThickness: 3,
92            pointMarker: new EllipsePointMarker(wasmContext, {
93                width: 7,
94                height: 7,
95                fill: appTheme.VividSkyBlue,
96                strokeThickness: 0,
97            }),
98            animation: new SweepAnimation({ duration: 800, delay: 0 }),
99        })
100    );
101
102    sciChartSurface.renderableSeries.add(
103        new FastLineRenderableSeries(wasmContext, {
104            dataSeries: new XyDataSeries(wasmContext, {
105                xValues: data1.xValues,
106                yValues: data1.yValues,
107                dataSeriesName: "y = x ^ 2.2",
108            }),
109            stroke: appTheme.VividPink,
110            strokeThickness: 3,
111            pointMarker: new EllipsePointMarker(wasmContext, {
112                width: 7,
113                height: 7,
114                fill: appTheme.VividPink,
115                strokeThickness: 0,
116            }),
117            animation: new SweepAnimation({ duration: 800, delay: 0 }),
118        })
119    );
120
121    sciChartSurface.renderableSeries.add(
122        new FastLineRenderableSeries(wasmContext, {
123            dataSeries: new XyDataSeries(wasmContext, {
124                xValues: data2.xValues,
125                yValues: data2.yValues,
126                dataSeriesName: "y = x ^ 2.4",
127            }),
128            stroke: appTheme.VividOrange,
129            strokeThickness: 3,
130            pointMarker: new EllipsePointMarker(wasmContext, {
131                width: 7,
132                height: 7,
133                fill: appTheme.VividOrange,
134                strokeThickness: 0,
135            }),
136            animation: new SweepAnimation({ duration: 800, delay: 0 }),
137        })
138    );
139
140    // Add some interactivity modifiers
141    sciChartSurface.chartModifiers.add(
142        new RubberBandXyZoomModifier(),
143        new MouseWheelZoomModifier(),
144        new ZoomExtentsModifier(),
145        new LegendModifier({ showCheckboxes: false })
146    );
147
148    sciChartSurface.zoomExtents();
149    return {
150        sciChartSurface,
151        wasmContext,
152        yAxisLogarithmic,
153        yAxisLinear,
154        xAxisLinear,
155        xAxisLogarithmic,
156    };
157};
158

Logarithmic Axis Example (JavaScript)

Overview

This example demonstrates how to create a high-performance SciChart.js chart featuring LogarithmicAxis configuration using JavaScript. The implementation plots exponential curves on both the X and Y axes while allowing runtime toggling between logarithmic and linear axis configurations.

Technical Implementation

The chart is asynchronously initialized using SciChartSurface.create, which loads the WebAssembly context and applies a custom theme for styling. Two LogarithmicAxis are configured with properties such as logBase, labelFormat, and labelPrecision; details of these configurations can be found in the Logarithmic Axis Documentation. Renderable series are created using FastLineRenderableSeries in combination with XyDataSeries to plot exponential curves, and each series is enhanced with a SweepAnimation for smooth visual transitions.

Features and Capabilities

The example showcases real-time update capabilities by enabling users to seamlessly switch between logarithmic and linear axis states at runtime. It integrates interactive modifiers such as RubberBandXyZoomModifier and MouseWheelZoomModifier to facilitate intuitive zooming and panning. Additionally, the application of custom theming—including grid line brushes and title styling—illustrates how visual aspects can be tailored to meet specific design requirements. For additional context on building high-performance charts, refer to Getting Started with SciChart JS.

Integration and Best Practices

Despite being a JavaScript example, the implementation follows best practices in asynchronous initialization, interactive behavior, and dynamic configuration. The runtime axis switching is handled by toggling the visibility and primary status of the axes, ensuring that the currently active axes are correctly bound to the series data; this approach is in line with the guidance provided in the SciChart.js Documentation. Developers looking to optimize performance and customize their charts further can benefit from exploring the available Performance Tips & Tricks provided by SciChart.js.

javascript Chart Examples & Demos

See Also: Scientific & Medical Charts (10 Demos)

JavaScript Vital Signs ECG/EKG Medical Demo | SciChart.js

JavaScript Vital Signs ECG/EKG Medical Demo

In this example we are simulating four channels of data showing that SciChart.js can be used to draw real-time ECG/EKG charts and graphs to monitor heart reate, body temperature, blood pressure, pulse rate, SPO2 blood oxygen, volumetric flow and more.

LiDAR 3D Point Cloud of Geospatial Data | SciChart.js

LiDAR 3D Point Cloud of Geospatial Data

Demonstrating the capability of SciChart.js to create JavaScript 3D Point Cloud charts and visualize LiDAR data from the UK Defra Survey.

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

Realtime Audio Spectrum Analyzer Chart | SciChart.js Demo

Realtime Audio Spectrum Analyzer Chart Example

See the frequency of recordings with the JavaScript audio spectrum analyzer example from SciChart. This real-time visualizer demo uses a Fourier Transform.

Realtime Audio Analyzer Bars Demo | SciChart.js Demo

Realtime Audio Analyzer Bars Demo

Demonstrating the capability of SciChart.js to create a JavaScript Audio Analyzer Bars and visualize the Fourier-Transform of an audio waveform in realtime.

Interactive Waterfall Chart | Javascript Charts | SciChart.js

Interactive Waterfall Spectral Chart

Demonstrates how to create a Waterfall chart in SciChart.js, showing chromotragraphy data with interactive selection of points.

Interactive Phasor Diagram chart | Javascript Charts | SciChart.js

Phasor Diagram Chart Example

See the JavaScript Phasor Diagram example to combine a Cartesian surface with a Polar subsurface. Get seamless JS integration with SciChart. View demo now.

NEW!
JavaScript Correlation Plot | Javascript Charts | SciChart.js

JavaScript Correlation Plot

Create JavaScript Correlation Plot with high performance SciChart.js. Easily render pre-defined point types. Supports custom shapes. Get your free trial now.

NEW!
Semiconductors Dashboard | JavaScript Charts | SciChart.js

Semiconductors Dashboard

JavaScript **Semiconductors Dashboard** using SciChart.js, by leveraging the **FastRectangleRenderableSeries**, and its `customTextureOptions` property to have a custom tiling texture fill.

NEW!
Wafer Analysis Chart | JavaScript Charts | SciChart.js

Wafer Analysis Chart

JavaScript **Wafer Analysis Chart** using SciChart.js, by leveraging the **FastRectangleRenderableSeries**, and crossfilter to enable live filtering.

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