Our team demonstrates how to create a JavaScript 3D Bubble Chart using SciChart.js, capable of creating detailed 3D JavaScript Charts.
drawExample.ts
index.html
vanilla.ts
ExampleDataProvider.ts
theme.ts
1import { appTheme } from "../../../theme";
2
3import {
4 SciChart3DSurface,
5 CameraController,
6 Vector3,
7 MouseWheelZoomModifier3D,
8 OrbitModifier3D,
9 ResetCamera3DModifier,
10 NumericAxis3D,
11 NumberRange,
12 ScatterRenderableSeries3D,
13 XyzDataSeries3D,
14 SpherePointMarker3D,
15 TGradientStop,
16 parseColorToUIntArgb,
17 TooltipModifier3D,
18 SeriesInfo3D,
19 TooltipSvgAnnotation3D,
20 XyzSeriesInfo3D,
21 IPointMetadata3D,
22} from "scichart";
23
24import {
25 fetchPopulationDataData,
26 TMappedPopulationData,
27 TPopulationMetadata,
28} from "../../../ExampleData/ExampleDataProvider";
29
30const initializeChart = async (rootElement: string | HTMLDivElement) => {
31 const { sciChart3DSurface, wasmContext } = await SciChart3DSurface.create(rootElement, {
32 theme: appTheme.SciChartJsTheme,
33 });
34 sciChart3DSurface.camera = new CameraController(wasmContext, {
35 position: new Vector3(-141.6, 310.29, 393.32),
36 target: new Vector3(0, 50, 0),
37 });
38
39 sciChart3DSurface.chartModifiers.add(
40 new MouseWheelZoomModifier3D(),
41 new OrbitModifier3D(),
42 new ResetCamera3DModifier()
43 );
44
45 const tooltipModifier = new TooltipModifier3D({ tooltipLegendOffsetX: 10, tooltipLegendOffsetY: 10 });
46 tooltipModifier.tooltipDataTemplate = (seriesInfo: SeriesInfo3D, svgAnnotation: TooltipSvgAnnotation3D) => {
47 const valuesWithLabels: string[] = [];
48 if (seriesInfo && seriesInfo.isHit) {
49 const md = (seriesInfo as XyzSeriesInfo3D).pointMetadata as TPopulationMetadata;
50 valuesWithLabels.push(md.country);
51 valuesWithLabels.push(`Life Expectancy: ${seriesInfo.xValue}`);
52 valuesWithLabels.push(`GDP Per Capita: ${seriesInfo.yValue}`);
53 valuesWithLabels.push(`Year: ${seriesInfo.zValue}`);
54 }
55 return valuesWithLabels;
56 };
57 const defaultTemplate = tooltipModifier.tooltipSvgTemplate;
58 tooltipModifier.tooltipSvgTemplate = (seriesInfo: SeriesInfo3D, svgAnnotation: TooltipSvgAnnotation3D) => {
59 if (seriesInfo) {
60 const md = (seriesInfo as XyzSeriesInfo3D).pointMetadata as TPopulationMetadata;
61 svgAnnotation.containerBackground = md.color;
62 svgAnnotation.textStroke = "white";
63 }
64 return defaultTemplate(seriesInfo, svgAnnotation);
65 };
66 sciChart3DSurface.chartModifiers.add(tooltipModifier);
67
68 sciChart3DSurface.xAxis = new NumericAxis3D(wasmContext, {
69 axisTitle: "Life Expectancy",
70 visibleRange: new NumberRange(30, 85),
71 labelPrecision: 0,
72 });
73 sciChart3DSurface.yAxis = new NumericAxis3D(wasmContext, {
74 axisTitle: "Gdp Per Capita",
75 visibleRange: new NumberRange(0, 50000),
76 labelPrecision: 0,
77 });
78 sciChart3DSurface.zAxis = new NumericAxis3D(wasmContext, {
79 axisTitle: "Year",
80 visibleRange: new NumberRange(1950, 2010),
81 labelPrecision: 0,
82 });
83
84 const renderableSeries = new ScatterRenderableSeries3D(wasmContext, {
85 pointMarker: new SpherePointMarker3D(wasmContext, { size: 10 }),
86 opacity: 0.9,
87 dataSeries: new XyzDataSeries3D(wasmContext),
88 });
89
90 sciChart3DSurface.renderableSeries.add(renderableSeries);
91
92 const setData = (data: TMappedPopulationData) => {
93 const { lifeExpectancy, gdpPerCapita, year, metadata } = data;
94
95 (renderableSeries.dataSeries as XyzDataSeries3D).appendRange(lifeExpectancy, gdpPerCapita, year, metadata);
96 };
97
98 return { sciChartSurface: sciChart3DSurface, setData };
99};
100
101export const drawExample = async (rootElement: string | HTMLDivElement) => {
102 const [chart, data] = await Promise.all([initializeChart(rootElement), fetchPopulationDataData()]);
103 chart.setData(data);
104
105 return chart;
106};
107This example demonstrates the creation of an interactive 3D bubble chart using SciChart.js in a JavaScript environment. The chart leverages the power of WebAssembly for high-performance rendering and offers advanced features such as custom tooltip rendering, interactive 3D modifiers, and efficient data series management.
The chart is initialized by creating a new SciChart3DSurface with a WebAssembly context, as described in the 3D Tutorial. Asynchronous initialization is handled using Promise.all to ensure that both the chart setup and data fetching complete before rendering. Interactive modifiers such as MouseWheelZoomModifier3D, OrbitModifier3D, and ResetCamera3DModifier are added to enable smooth 3D navigation; learn more in the Orbit Modifier 3D documentation. Custom camera control is achieved via the CameraController, allowing for precise positioning of the 3D view.
The example features a sophisticated custom tooltip implementation using TooltipModifier3D. Data points in the scatter renderable series are enriched with metadata (such as country, life expectancy, GDP per capita, and year), and tooltips are rendered using custom data and SVG templates as outlined in the Tooltip Modifier 3D documentation. Additionally, each of the 3D axes is configured using NumericAxis3D with specified visible ranges and label precision. Detailed information on axis configuration can be found in the NumericAxis3D API documentation.
Resource cleanup is managed via a destructor function that calls the delete method on the SciChartSurface, in accordance with best practices described in the Memory Best Practices documentation. The asynchronous pattern using Promise.all is further supported by guidelines discussed in the MDN Promise.all documentation. By integrating these advanced features in a JavaScript framework, the example illustrates how to build high-performance, customizable 3D charts using SciChart.js.

Design a JavaScript 3D Surface Mesh Chart with SciChart.js - feature-rich JavaScript chart library. Represent 2D data in a 3D map. Get your free demo.

Create detailed JavaScript 3D Line Chart using SciChart's 5-star rated JavaScript chart library. Supports large datasets. Get your free demo now.

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

Demonstrating the capability of SciChart.js to create a composite 2D & 3D Chart application. An example like this could be used to visualize Tenor curves in a financial setting, or other 2D/3D data combined on a single screen.

Design a JavaScript 3D Surface Mesh Chart with SciChart.js - feature-rich JavaScript chart library. Represent 2D data in a 3D map. Get your free demo.

Create detailed JavaScript 3D Column Chart using SciChart's 5-star rated JavaScript chart library. Supports large datasets

Create advanced JavaScript 3D Styling Demo using SciChart's 5-star rated JavaScript chart library. Explore axis styling, plane visibility and multiple point markers.