JavaScript Polar Spline Line Chart

Creates a JavaScript Polar Spline Line Chart using SciChart.js, using either a Cubic spline, or polar interpolation

src/drawExample.ts
import {
    PolarMouseWheelZoomModifier,
    PolarZoomExtentsModifier,
    PolarPanModifier,
    PolarNumericAxis,
    SciChartPolarSurface,
    EPolarAxisMode,
    NumberRange,
    EAxisAlignment,
    EPolarLabelMode,
    PolarLegendModifier,
    PolarLineRenderableSeries,
    XyDataSeries,
    SplineRenderDataTransform,
    WaveAnimation,
} from "scichart";
import { appTheme } from "./appTheme";

export const drawExample = async (rootElement: string | HTMLDivElement) => {
    const { sciChartSurface, wasmContext } = await SciChartPolarSurface.create(rootElement, {
        theme: appTheme.SciChartJsTheme,
    });

    const radialYAxis = new PolarNumericAxis(wasmContext, {
        polarAxisMode: EPolarAxisMode.Radial,
        axisAlignment: EAxisAlignment.Right,
        visibleRange: new NumberRange(0, 6),
        drawMinorTickLines: false,
        drawMajorTickLines: false,
        useNativeText: true,
        drawMinorGridLines: false,
        zoomExtentsToInitialRange: true,
        labelPrecision: 0,
        innerRadius: 0.1, // donut hole
    });
    sciChartSurface.yAxes.add(radialYAxis);

    const polarXAxis = new PolarNumericAxis(wasmContext, {
        polarAxisMode: EPolarAxisMode.Angular,
        axisAlignment: EAxisAlignment.Top,

        polarLabelMode: EPolarLabelMode.Parallel,

        autoTicks: false,
        majorDelta: 1,

        useNativeText: true,
        flippedCoordinates: true, // go clockwise
        totalAngle: Math.PI,
        labelPrecision: 0,
    });
    sciChartSurface.xAxes.add(polarXAxis);

    const ANIMATION_DURATION = 500;
    const xValues = [0, 1, 2, 3, 4, 5, 6, 7, 8];
    const yValues = [3, 4, 2, 4, 5, 5, 3, 2, 4];

    // 1. regular polar line
    const regularPolarLine = new PolarLineRenderableSeries(wasmContext, {
        dataSeries: new XyDataSeries(wasmContext, {
            xValues,
            yValues,
            dataSeriesName: "Original Data",
        }),
        stroke: "#CCCCCC",
        strokeThickness: 3,
    });

    // 2. cubic polar line
    const cubicPolarLine = new PolarLineRenderableSeries(wasmContext, {
        dataSeries: new XyDataSeries(wasmContext, {
            xValues,
            yValues,
            dataSeriesName: "Cubic",
        }),
        stroke: appTheme.VividOrange,
        strokeThickness: 5,
        animation: new WaveAnimation({ duration: ANIMATION_DURATION, delay: ANIMATION_DURATION }),
    });
    // Add cubic bezier transform
    const cubicTransform = new SplineRenderDataTransform(cubicPolarLine, wasmContext, [
        cubicPolarLine.drawingProviders[0],
    ]);
    cubicTransform.interpolationPoints = 30;
    cubicPolarLine.renderDataTransform = cubicTransform;

    // 3. interpolated polar line
    const interpolatedPolarLine = new PolarLineRenderableSeries(wasmContext, {
        dataSeries: new XyDataSeries(wasmContext, {
            xValues,
            yValues,
            dataSeriesName: "Interpolated",
        }),
        interpolateLine: true, //
        stroke: appTheme.VividPurple,
        strokeThickness: 5,
        animation: new WaveAnimation({ duration: ANIMATION_DURATION, delay: 2 * ANIMATION_DURATION }),
    });

    sciChartSurface.renderableSeries.add(regularPolarLine, cubicPolarLine, interpolatedPolarLine);

    sciChartSurface.chartModifiers.add(
        new PolarPanModifier(),
        new PolarZoomExtentsModifier(),
        new PolarMouseWheelZoomModifier(),
        new PolarLegendModifier({
            showCheckboxes: true,
        })
    );

    return { sciChartSurface, wasmContext };
};

Polar Spline Line Chart – JavaScript

Overview

Compare the original data with cubic-spline and polar-interpolated lines. Each series uses the same points, so you can see how the interpolation changes the path between them.

How it works

The chart uses SciChartPolarSurface with radial and angular axes. SplineRenderDataTransform smooths one line; setting interpolateLine: true draws another as arcs between polar points. See the spline transform API and polar line series guide.

Interactions

WaveAnimation reveals the lines in sequence. Drag to pan, scroll to zoom, and use the legend checkboxes to show or hide each series.

Lifecycle

Call sciChartSurface.delete() when the chart is no longer needed to release its resources.