JavaScript Polar Map Example

Demonstrates how to create a Polar Map Example using our PolarTriangleRenderableSeries class, along with a triangulation alorithm.

Fullscreen

Edit

 Edit

Docs

drawExample.ts

index.html

vanilla.ts

constrainedDelaunayTriangulation.ts

Copy to clipboard
Minimise
Fullscreen
1import {
2    NumberRange,
3    XyDataSeries,
4    ETriangleSeriesDrawMode,
5    PolarPanModifier,
6    PolarZoomExtentsModifier,
7    PolarMouseWheelZoomModifier,
8    PolarTriangleRenderableSeries,
9    PolarNumericAxis,
10    EPolarAxisMode,
11    EAxisAlignment,
12    SciChartPolarSurface,
13} from "scichart";
14
15import constrainedDelaunayTriangulation from "./constrainedDelaunayTriangulation";
16
17export const drawExample = async (rootElement: string | HTMLDivElement) => {
18    // Create a SciChartSurface
19    const { wasmContext, sciChartSurface } = await SciChartPolarSurface.create(rootElement);
20
21    sciChartSurface.debugRendering = false;
22
23    let showFromSouthPole = false;
24
25    const setView = (positionFromSPole: boolean) => {
26        showFromSouthPole = positionFromSPole;
27
28        sciChartSurface.xAxes.clear();
29        sciChartSurface.yAxes.clear();
30        sciChartSurface.renderableSeries.clear(true);
31
32        const xAxis = new PolarNumericAxis(wasmContext, {
33            polarAxisMode: EPolarAxisMode.Angular,
34            visibleRange: new NumberRange(-180, 180), // longitude
35            flippedCoordinates: showFromSouthPole ? true : false,
36            axisAlignment: EAxisAlignment.Bottom,
37            useNativeText: true,
38            drawMajorBands: false,
39            drawMajorGridLines: false,
40            drawMajorTickLines: false,
41            drawMinorGridLines: false,
42            drawMinorTickLines: false,
43            labelPrecision: 0
44        });
45        sciChartSurface.xAxes.add(xAxis);
46
47        const yAxis = new PolarNumericAxis(wasmContext, {
48            polarAxisMode: EPolarAxisMode.Radial,
49            visibleRange: new NumberRange(-90, 90), // latitude
50            axisAlignment: EAxisAlignment.Left,
51            flippedCoordinates: showFromSouthPole ? false : true,
52            useNativeText: true,
53            drawMajorBands: false,
54            drawMajorGridLines: false,
55            drawMajorTickLines: false,
56            drawMinorGridLines: false,
57            drawMinorTickLines: false,
58            labelPrecision: 0
59        });
60        sciChartSurface.yAxes.add(yAxis);
61    };
62
63    setView(true);
64
65    const [min, max] = [140, 1379302771]; // population min max
66
67    function interpolateColor(min: number, max: number, value: number) {
68        // Clamp value between min and max
69        value = Math.max(min, Math.min(max, value));
70        // Normalize to [0,1]
71        let t = (value - min) / (max - min);
72
73        // Parse hex colors to RGB
74        function hexToRgb(hex: string) {
75            hex = hex.replace(/^#/, "");
76            if (hex.length === 3)
77                hex = hex
78                    .split("")
79                    .map((x) => x + x)
80                    .join("");
81            const num = parseInt(hex, 16);
82            return [num >> 16, (num >> 8) & 255, num & 255];
83        }
84
85        // Interpolate between two RGB colors
86        function lerp(a: number, b: number, t: number) {
87            return Math.round(a + (b - a) * t);
88        }
89
90        const colorA = hexToRgb("#ffffff");
91        const colorB = hexToRgb("#1e3489");
92        const r = lerp(colorA[0], colorB[0], t);
93        const g = lerp(colorA[1], colorB[1], t);
94        const b = lerp(colorA[2], colorB[2], t);
95
96        // Convert back to hex
97        return "#" + [r, g, b].map((x) => x.toString(16).padStart(2, "0")).join("");
98    }
99
100    let dataArray: { name: string; gdp: number; population: number; areaData: number[][] }[] = [];
101
102    const setMapJson = (mapData: { features: any[] }) => {
103        dataArray = [];
104
105        mapData?.features.forEach((state, i) => {
106            if (state.geometry.type === "Polygon") {
107                let area = state.geometry.coordinates[0];
108                area.pop();
109                let areaData = [].concat(...constrainedDelaunayTriangulation(area));
110
111                dataArray.push({
112                    name: state.properties.NAME,
113                    gdp: +state.properties.GDP_MD_EST,
114                    population: +state.properties.POP_EST,
115                    areaData,
116                });
117            } else {
118                let polyArea = state.geometry.coordinates;
119
120                if (state.properties.SOVEREIGNT === "Antarctica" && showFromSouthPole === false) {
121                    return;
122                }
123
124                polyArea.forEach((a: any[]) => {
125                    let area = a[0];
126
127                    area.pop();
128                    let areaData = [].concat(...constrainedDelaunayTriangulation(area));
129
130                    dataArray.push({
131                        name: state.properties.NAME,
132                        gdp: +state.properties.GDP_MD_EST,
133                        population: +state.properties.POP_EST,
134                        areaData,
135                    });
136                });
137            }
138        });
139    };
140
141    const setMap = () => {
142        sciChartSurface.renderableSeries.clear(true);
143
144        const series = dataArray.map((d, i) => {
145            const dataSeries = new XyDataSeries(wasmContext, {
146                xValues: d.areaData.map((p) => p[0]),
147                yValues: d.areaData.map((p) => p[1]),
148            });
149
150            const triangleSeries = new PolarTriangleRenderableSeries(wasmContext, {
151                dataSeries: dataSeries,
152                drawMode: ETriangleSeriesDrawMode.List,
153                fill: interpolateColor(min, max, d.population),
154                opacity: 0.9,
155            });
156
157            return triangleSeries;
158        });
159
160        sciChartSurface.renderableSeries.add(...series);
161    };
162
163    sciChartSurface.chartModifiers.add(new PolarPanModifier());
164    sciChartSurface.chartModifiers.add(new PolarZoomExtentsModifier());
165    sciChartSurface.chartModifiers.add(new PolarMouseWheelZoomModifier());
166    return { sciChartSurface, wasmContext, setMapJson, setMap, setView };
167};
168

Polar Map Example - JavaScript

Overview

This example demonstrates how to create a polar map visualization using SciChart.js in JavaScript. The implementation renders geographic data as a series of colored triangles on a polar coordinate system, with options to view from either the North or South pole.

Technical Implementation

The chart uses a PolarNumericAxis for angular (longitude) and radial (latitude) coordinates. Geographic polygons are converted to triangles using a constrained Delaunay triangulation algorithm. Each triangle's color represents population density, calculated via an interpolation function between white and blue.

Features and Capabilities

The visualization includes interactive modifiers like PolarPanModifier and PolarZoomExtentsModifier. The flippedCoordinates property enables switching between North and South pole views dynamically.

Integration and Best Practices

The example follows best practices for WebAssembly initialization and surface disposal. Geographic data is loaded asynchronously from a JSON file, with proper error handling.

javascript Chart Examples & Demos

See Also: Polar Charts (21 Demos)

JavaScript Polar Line Chart | Javascript Charts | SciChart.js

JavaScript Polar Line Chart

Explore the React Polar Line Chart example to create data labels, line interpolation, gradient palette stroke and startup animations. Try the SciChart Demo.

JavaScript Polar Spline Line Chart | SciChart.js Demo

JavaScript Polar Spline Line Chart

Try the JavaScript Polar Spline Line Chart example to see SciChart's GPU-accelerated rendering in action. Choose a cubic spline or polar interpolation. View demo.

JavaScript Multi-Cycle Polar Line | SciChart.js Demo

JavaScript Multi Cycle-Polar Line Example

Create a JavaScript Multi-Cycle Polar Chart to plot data over multiple cycles and visualize patterns over time. This example shows surface temperature by month.

JavaScript Polar Column Chart | Polar Bar Chart | SciChart

JavaScript Polar Column | Polar Bar

Try the JavaScript Polar Column or Bar Chart example to render bars in a polar layout with gradient fills and animations. Use SciChart for seamless integrations.

JavaScript Polar Column Category Chart | SciChart.js Demo

JavaScript Polar Column Category Chart

Create a JavaScript Polar Colum Category chart visualizing UK consumer price changes. Try the demo with a custom positive/negative threshold fill and stroke.

JavaScript Polar Range Column Chart | SciChart.js Demo

JavaScript Polar Range Column Chart

Create a JavaScript Polar Range Column Chart with SciChart. This example displays monthly minimum and maximum temperatures within a Polar layout. Try the demo.

JavaScript Windrose Plot | Polar Stacked Radial Column Chart

JavaScript Windrose Plot | Polar Stacked Radial Column Chart

View the JavaScript Windrose Chart example to display directional data with stacked columns in a polar layout. Try the polar chart demo with customizable labels

JavaScript Polar Sunburst Chart | Javascript Charts | SciChart.js

JavaScript Polar Sunburst Chart

See the JavaScript Sunburst Chart example with multiple levels, smooth animation transitions and dynamically updating segment colors. Try the SciChart demo.

JavaScript Polar Radial Column Chart | SciChart.js Demo

JavaScript Polar Radial Column Chart

View the JavaScript Radial Column Chart example to see the difference that SciChart has to offer. Switch radial and angular axes and add interactive modifiers.

JavaScript Stacked Radial Column Chart | Stacked Radial Bar Chart

JavaScript Stacked Radial Column Chart | Stacked Radial Bar Chart

This JavaScript Stacked Radial Bar Chart example shows Olympic medal data by country. Try the demo for yourself with async initialization and theme application.

JavaScript Polar Area Chart | Polar Mountain Chart | SciChart

JavaScript Polar Area Chart | Polar Mountain Chart

The JavaScript Polar Area Chart example, also known as Nightingale Rose Chart, renders an area series with polar coordinates with interactive legend controls.

JavaScript Polar Stacked Radial Mountain Chart | SciChart

JavaScript Polar Stacked Radial Mountain Chart

Try the JavaScript Stacked Radial Mountain Chart example to show multiple datasets on a polar layout with a stacked mountain series and animated transitions.

JavaScript Polar Band | Polar Error Bands Chart | SciChart

JavaScript Polar Band | Polar Error Bands Chart

Create a JavaScript Polar Chart with regular and interpolated error bands. Enhance a standard chart with shaded areas to show upper and lower data boundaries.

JavaScript Polar Scatter Chart | Javascript Charts | SciChart.js

JavaScript Polar Scatter Chart

Build a JavaScript Polar Scatter Chart with this example to render multiple scatter series on radial and angular axes. Try the flexible SciChart demo today.

JavaScript Polar Radar Chart | Spider Radar Chart | SciChart

JavaScript Polar Radar Chart

View the JavaScript Polar Radar Chart example. Also known as the Spider Radar Chart, view the scalability and stability that SciChart has to offer. Try demo.

JavaScript Polar Gauge Chart | Circular Gauge Chart

JavaScript Gauge Charts

Create JavaScript Gauge Charts, including a JavaScript Circular Gauge Dashboard, with user-friendly initialization and responsive design. Give SciChart a go.

JavaScript Arc Gauge & FIFO Scrolling Charts Dashboard

JavaScript Arc Gauge & FIFO Scrolling Charts Dashboard Example

View JavaScript Arc Gauge Charts alongside FIFO Scrolling Charts, all on the same dashboard with real-time, high-performance data rendering. Try the demo.

JavaScript Polar Uniform Heatmap Chart | SciChart.js Demo

JavaScript Polar Uniform Heatmap Chart

Try SciChart's JavaScript Polar Heatmap example to combine a polar heatmap with a legend component. Supports responsive design and chart and legend separation.

JS Polar Heatmap | B-Mode Image Ultrasound | Medical Heatmap

JavaScript Polar Heatmap | B-Mode Image Ultrasound | Medical Heatmap

No description available for this example yet

JavaScript Polar Partial Arc | Javascript Charts | SciChart.js

JavaScript Polar Partial Arc

Create a JavaScript Polar Partial Arc that bends from a full Polar Circle to a Cartesian-like arc. Try the demo to display an arc segment with Polar coordinates.

JavaScript Polar Axis Label Modes | SciChart.js Demo

JavaScript Polar Axis Label Modes

Create a JavaScript Polar Axis Label with SciChart. This demo shows the various label modes for Polar Axes – all optimised for pan, zoom, and mouse wheel.

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