HelpBot Assistant

How can I help you?

Getting started with React 3D Chart component

24 Feb 202624 minutes to read

This section describes the steps to create a simple 3D Chart and demonstrates the basic usage of the 3D Chart component.

A quick video overview of the React 3D Charts setup is available:

Dependencies

Below is the list of minimum dependencies required to use the 3D Chart component.

|-- @syncfusion/ej2-react-charts
    |-- @syncfusion/ej2-data
    |-- @syncfusion/ej2-react-base
    |-- @syncfusion/ej2-pdf-export
    |-- @syncfusion/ej2-file-utils
    |-- @syncfusion/ej2-compression
    |-- @syncfusion/ej2-svg-base

Once you install @syncfusion/ej2-react-charts, the other required dependencies will be installed automatically along with the main package.

Installation and configuration

Create a React application

To easily set up a React application, use the Vite CLI (npm create vite), which provides a faster development environment, smaller bundle sizes, and optimized builds compared to traditional tools like create-react-app. For detailed steps, refer to the Vite installation instructions. Vite sets up your environment using JavaScript and optimizes your application for production.

Note: To create a React application using create-react-app instead, refer to this documentation for more details.

To create a new React application, run the following command.

npm create vite@latest my-app

This command will prompt you for a few settings for the new project, such as selecting a framework and a variant.

Initial_setup

To set up a React application in TypeScript environment, run the following command.

npm create vite@latest my-app -- --template react-ts
cd my-app
npm run dev

To set up a React application in JavaScript environment, run the following command.

npm create vite@latest my-app -- --template react
cd my-app
npm run dev

Install Syncfusion® 3D Chart package

All the available Essential® JS 2 packages are published in the npmjs.com public registry.

To install the Syncfusion® 3D Chart package, use the following command

npm install @syncfusion/ej2-react-charts --save

The –save will instruct NPM to include the 3D Chart package inside of the dependencies section of the package.json.

Add 3D Chart to the project

Add the 3D Chart component to src/App.tsx using the following code.

import { Chart3DComponent } from '@syncfusion/ej2-react-charts';
import * as React from 'react';
function App() {
  return (<Chart3DComponent />);
}
export default App;
import { Chart3DComponent } from '@syncfusion/ej2-react-charts';
import * as React from 'react';
function App() {
  return (<Chart3DComponent />);
}
export default App;

Now run the npm run dev command in the console to start the development server. This command compiles your code and serves the application locally, opening it in the browser.

npm run dev

The below example shows a basic 3D Chart.

import { Chart3DComponent } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';
function App() {
    return <Chart3DComponent id='charts' />;
}
;
export default App;
createRoot(document.getElementById('charts')).render(<App />);
import { Chart3DComponent } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';

function App() {
  return <Chart3DComponent id='charts' />
};
export default App;
createRoot(document.getElementById('charts')).render(<App />);

Module injection

3D Chart components are segregated into individual feature-wise modules. In order to use a particular feature, you need to inject its feature service in the 3D Chart component. In the current application, we are going to modify the above basic 3D Chart to visualize sales data for a particular year. For this application we are going to use column series, tooltip, data label, category axis and legend feature of the 3D Chart. Please find relevant feature service name and description as follows.

  • ColumnSeries3D - Inject this module in to services to use column series.
  • Legend3D - Inject this module in to services to use legend feature.
  • Tooltip3D - Inject this module in to services to use tooltip feature.
  • DataLabel3D - Inject this module in to services to use datalabel feature.
  • Category3D - Inject this module in to services to use category feature.

Import the above-mentioned modules from the chart package and inject them into the services section of the 3D Chart component as follows.

import { Chart3DComponent, ColumnSeries3D, Legend3D, Tooltip3D, DataLabel3D, Category3D, Inject } from '@syncfusion/ej2-react-charts';
import * as React from "react";

function App() {
  return <Chart3DComponent id='charts'>
    <Inject services={[ColumnSeries3D, Legend3D, Tooltip3D, DataLabel3D, Category3D]}/>
  </Chart3DComponent>;
}
export default App;
import { Chart3DComponent, ColumnSeries3D, Legend3D, Tooltip3D, DataLabel3D, Category3D, Inject } from '@syncfusion/ej2-react-charts';
import * as React from "react";
function App() {
    return <Chart3DComponent id='charts'>
    <Inject services={[ColumnSeries3D, Legend3D, Tooltip3D, DataLabel3D, Category3D]}/>
  </Chart3DComponent>;
}
export default App;

Populate 3D Chart with data

This section explains how to plot the following JSON data to the 3D Chart.

export let data = [
    { x: 'Tesla', y: 137429 },
    { x: 'Aion', y: 80308 },
    { x: 'Wuling', y: 76418 },
    { x: 'Changan', y: 52849 },
    { x: 'Geely', y: 47234 },
    { x: 'Nio', y: 31041 },
    { x: 'Neta', y: 22449 },
    { x: 'BMW', y: 18733 }
];
export let data: Object[] = [
    { x: 'Tesla', y: 137429 },
    { x: 'Aion', y: 80308 },
    { x: 'Wuling', y: 76418 },
    { x: 'Changan', y: 52849 },
    { x: 'Geely', y: 47234 },
    { x: 'Nio', y: 31041 },
    { x: 'Neta', y: 22449 },
    { x: 'BMW', y: 18733 }
];

Add series to the 3D Chart using the <Chart3DSeriesCollectionDirective> and <Chart3DSeriesDirective> components. Map the JSON fields x and y to the series xName and yName properties, and set the JSON array as the dataSource property.

Since the JSON contains category data, set the valueType for the horizontal axis (primaryXAxis) to Category. By default, the axis valueType is Numeric.

import { Chart3DComponent, Chart3DSeriesCollectionDirective, Chart3DSeriesDirective, Inject, Category3D, ColumnSeries3D } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';

export let data = [
    { x: 'Tesla', y: 137429 },
    { x: 'Aion', y: 80308 },
    { x: 'Wuling', y: 76418 },
    { x: 'Changan', y: 52849 },
    { x: 'Geely', y: 47234 },
    { x: 'Nio', y: 31041 },
    { x: 'Neta', y: 22449 },
    { x: 'BMW', y: 18733 }
];

function App() {
    return (<Chart3DComponent id='charts' style= primaryXAxis=
        wallColor='transparent'
        primaryYAxis= enableRotation={true} rotation={7} tilt={10} depth={100}>
        <Inject services={[ColumnSeries3D, Category3D]} />
        <Chart3DSeriesCollectionDirective >
            <Chart3DSeriesDirective dataSource={data} xName='x' yName='y' type='Column'>
            </Chart3DSeriesDirective>
        </Chart3DSeriesCollectionDirective>
    </Chart3DComponent>)
}
;
export default App;
createRoot(document.getElementById('charts')).render(<App />);
import { Category3D, Chart3DComponent, Chart3DSeriesCollectionDirective, Chart3DSeriesDirective, ColumnSeries3D, Inject } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';

export let data: Object[] = [
  { x: 'Tesla', y: 137429 },
  { x: 'Aion', y: 80308 },
  { x: 'Wuling', y: 76418 },
  { x: 'Changan', y: 52849 },
  { x: 'Geely', y: 47234 },
  { x: 'Nio', y: 31041 },
  { x: 'Neta', y: 22449 },
  { x: 'BMW', y: 18733 }
];


function App() {
  return (<Chart3DComponent id='charts' style= primaryXAxis=
    wallColor='transparent'
    primaryYAxis= enableRotation={true} rotation={7} tilt={10} depth={100}>
    <Inject services={[ColumnSeries3D, Category3D]} />
    <Chart3DSeriesCollectionDirective >
      <Chart3DSeriesDirective dataSource={data} xName='x' yName='y' type='Column'>
      </Chart3DSeriesDirective>
    </Chart3DSeriesCollectionDirective>
  </Chart3DComponent>)
};
export default App;
createRoot(document.getElementById('charts')).render(<App />);

Add 3D Chart title

You can add a title using the title property to the 3D Chart to provide quick information to the user about the data plotted in the 3D Chart.

import { Chart3DComponent, Chart3DSeriesCollectionDirective, Chart3DSeriesDirective, Inject, Category3D, ColumnSeries3D } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';

export let data = [
    { x: 'Tesla', y: 137429 },
    { x: 'Aion', y: 80308 },
    { x: 'Wuling', y: 76418 },
    { x: 'Changan', y: 52849 },
    { x: 'Geely', y: 47234 },
    { x: 'Nio', y: 31041 },
    { x: 'Neta', y: 22449 },
    { x: 'BMW', y: 18733 }
];

function App() {
    return (<Chart3DComponent id='charts' style= primaryXAxis=
        wallColor='transparent'
        primaryYAxis= enableRotation={true} rotation={7} tilt={10} depth={100} title='Top Selling Electric Cars in China'>
        <Inject services={[ColumnSeries3D, Category3D]} />
        <Chart3DSeriesCollectionDirective >
            <Chart3DSeriesDirective dataSource={data} xName='x' yName='y' type='Column'>
            </Chart3DSeriesDirective>
        </Chart3DSeriesCollectionDirective>
    </Chart3DComponent>);
}
;
export default App;
createRoot(document.getElementById('charts')).render(<App />);
import { Category3D, Chart3DComponent, Chart3DSeriesCollectionDirective, Chart3DSeriesDirective, ColumnSeries3D, Inject } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';

export let data: any[] = [
  { x: 'Tesla', y: 137429 },
  { x: 'Aion', y: 80308 },
  { x: 'Wuling', y: 76418 },
  { x: 'Changan', y: 52849 },
  { x: 'Geely', y: 47234 },
  { x: 'Nio', y: 31041 },
  { x: 'Neta', y: 22449 },
  { x: 'BMW', y: 18733 }
];


function App() {
  return (<Chart3DComponent id='charts' style= primaryXAxis=
    wallColor='transparent'
    primaryYAxis= enableRotation={true} rotation={7} tilt={10} depth={100} title='Top Selling Electric Cars in China'>
    <Inject services={[ColumnSeries3D, Category3D]} />
    <Chart3DSeriesCollectionDirective >
      <Chart3DSeriesDirective dataSource={data} xName='x' yName='y' type='Column'>
      </Chart3DSeriesDirective>
    </Chart3DSeriesCollectionDirective>
  </Chart3DComponent>)
};
export default App;
createRoot(document.getElementById('charts')).render(<App />);

Enable legend

You can use legend for the 3D Chart by setting the visible property to true in legendSettings object and by injecting the Legend3D module into the services.

import { Chart3DComponent, Chart3DSeriesCollectionDirective, Chart3DSeriesDirective, Inject, Legend3D, Category3D, ColumnSeries3D, Highlight3D } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';

export let data = [
    { x: 'Tesla', y: 137429 },
    { x: 'Aion', y: 80308 },
    { x: 'Wuling', y: 76418 },
    { x: 'Changan', y: 52849 },
    { x: 'Geely', y: 47234 },
    { x: 'Nio', y: 31041 },
    { x: 'Neta', y: 22449 },
    { x: 'BMW', y: 18733 }
];

function App() {
    return (<Chart3DComponent id='charts' style= primaryXAxis=
        wallColor='transparent'
        primaryYAxis= enableRotation={true} rotation={7} legendSettings= tilt={10} depth={100}>
        <Inject services={[ColumnSeries3D, Legend3D, Category3D, Highlight3D]} />
        <Chart3DSeriesCollectionDirective >
            <Chart3DSeriesDirective dataSource={data} xName='x' name='Sales' yName='y' type='Column'>
            </Chart3DSeriesDirective>
        </Chart3DSeriesCollectionDirective>
    </Chart3DComponent>);
}
;
export default App;
createRoot(document.getElementById('charts')).render(<App />);
import { Category3D, Chart3DComponent, Chart3DSeriesCollectionDirective, Chart3DSeriesDirective, Highlight3D, ColumnSeries3D, Legend3D, Inject } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';

export let data: any[] = [
  { x: 'Tesla', y: 137429 },
  { x: 'Aion', y: 80308 },
  { x: 'Wuling', y: 76418 },
  { x: 'Changan', y: 52849 },
  { x: 'Geely', y: 47234 },
  { x: 'Nio', y: 31041 },
  { x: 'Neta', y: 22449 },
  { x: 'BMW', y: 18733 }
];


function App() {
  return (<Chart3DComponent id='charts' style= primaryXAxis=
    wallColor='transparent'
    primaryYAxis= legendSettings= enableRotation={true} rotation={7} tilt={10} depth={100}>
    <Inject services={[ColumnSeries3D, Legend3D, Category3D, Highlight3D]} />
    <Chart3DSeriesCollectionDirective >
      <Chart3DSeriesDirective dataSource={data} xName='x' name='Sales' yName='y' type='Column'>
      </Chart3DSeriesDirective>
    </Chart3DSeriesCollectionDirective>
  </Chart3DComponent>)
};
export default App;
createRoot(document.getElementById('charts')).render(<App />);

Add data label

You can add data labels to improve the readability of the 3D Chart. This can be achieved by setting the visible property to true in the dataLabel object and by injecting DataLabel3D module into the services. Now, the data labels are arranged smartly based on series.

import { Chart3DComponent, Chart3DSeriesCollectionDirective, Chart3DSeriesDirective, Inject, Legend3D, DataLabel3D, Category3D, ColumnSeries3D, Highlight3D } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';

export let data = [
    { x: 'Tesla', y: 137429 },
    { x: 'Aion', y: 80308 },
    { x: 'Wuling', y: 76418 },
    { x: 'Changan', y: 52849 },
    { x: 'Geely', y: 47234 },
    { x: 'Nio', y: 31041 },
    { x: 'Neta', y: 22449 },
    { x: 'BMW', y: 18733 }
];

function App() {
    return (<Chart3DComponent id='charts' style= primaryXAxis=
        wallColor='transparent'
        primaryYAxis= enableRotation={true} rotation={7} tilt={10} depth={100} legendSettings=>
        <Inject services={[ColumnSeries3D, Legend3D, Category3D, DataLabel3D, Highlight3D]} />
        <Chart3DSeriesCollectionDirective >
            <Chart3DSeriesDirective dataSource={data} dataLabel= xName='x' name='Sales' yName='y' type='Column'>
            </Chart3DSeriesDirective>
        </Chart3DSeriesCollectionDirective>
    </Chart3DComponent>);
}
;
export default App;
createRoot(document.getElementById('charts')).render(<App />);
import { Category3D, Chart3DComponent, Chart3DSeriesCollectionDirective, Chart3DSeriesDirective, DataLabel3D, Highlight3D, ColumnSeries3D, Legend3D, Inject } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';

export let data: any[] = [
  { x: 'Tesla', y: 137429 },
  { x: 'Aion', y: 80308 },
  { x: 'Wuling', y: 76418 },
  { x: 'Changan', y: 52849 },
  { x: 'Geely', y: 47234 },
  { x: 'Nio', y: 31041 },
  { x: 'Neta', y: 22449 },
  { x: 'BMW', y: 18733 }
];


function App() {
  return (<Chart3DComponent id='charts' style= primaryXAxis=
    wallColor='transparent'
    primaryYAxis= enableRotation={true} rotation={7} tilt={10} depth={100} legendSettings=>
    <Inject services={[ColumnSeries3D, Legend3D, DataLabel3D, Category3D, Highlight3D]} />
    <Chart3DSeriesCollectionDirective >
      <Chart3DSeriesDirective dataLabel= dataSource={data} xName='x' name='Sales' yName='y' type='Column'>
      </Chart3DSeriesDirective>
    </Chart3DSeriesCollectionDirective>
  </Chart3DComponent>)
};
export default App;
createRoot(document.getElementById('charts')).render(<App />);

Enable tooltip

The tooltip is useful when you cannot display information by using the data labels due to space constraints. You can enable tooltip by setting the enable property as true in tooltip object and by injecting Tooltip3D module into the services.

import { Chart3DComponent, Chart3DSeriesCollectionDirective, Chart3DSeriesDirective, Inject, Legend3D, DataLabel3D, Category3D, Tooltip3D, ColumnSeries3D, Highlight3D } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';

export let data = [
    { x: 'Tesla', y: 137429 },
    { x: 'Aion', y: 80308 },
    { x: 'Wuling', y: 76418 },
    { x: 'Changan', y: 52849 },
    { x: 'Geely', y: 47234 },
    { x: 'Nio', y: 31041 },
    { x: 'Neta', y: 22449 },
    { x: 'BMW', y: 18733 }
];

function App() {
    return (<Chart3DComponent id='charts' style= primaryXAxis=
        wallColor='transparent'
        primaryYAxis= enableRotation={true} rotation={7} tilt={10} depth={100} tooltip= legendSettings=>
        <Inject services={[ColumnSeries3D, Legend3D, Tooltip3D, Category3D, DataLabel3D, Highlight3D]} />
        <Chart3DSeriesCollectionDirective >
            <Chart3DSeriesDirective dataSource={data} xName='x' name='Sales' yName='y' type='Column'>
            </Chart3DSeriesDirective>
        </Chart3DSeriesCollectionDirective>
    </Chart3DComponent>);
}
;
export default App;
createRoot(document.getElementById('charts')).render(<App />);
import { Category3D, Chart3DComponent, Chart3DSeriesCollectionDirective, Chart3DSeriesDirective, DataLabel3D, Highlight3D, ColumnSeries3D, Legend3D, Tooltip3D, Inject } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';

export let data: Object[] = [
  { x: 'Tesla', y: 137429 },
  { x: 'Aion', y: 80308 },
  { x: 'Wuling', y: 76418 },
  { x: 'Changan', y: 52849 },
  { x: 'Geely', y: 47234 },
  { x: 'Nio', y: 31041 },
  { x: 'Neta', y: 22449 },
  { x: 'BMW', y: 18733 }
];


function App() {
  return (<Chart3DComponent id='charts' style= primaryXAxis=
    wallColor='transparent'
    primaryYAxis= enableRotation={true} rotation={7} tilt={10} depth={100} tooltip= legendSettings=>
    <Inject services={[ColumnSeries3D, Legend3D, Tooltip3D, DataLabel3D, Category3D, Highlight3D]} />
    <Chart3DSeriesCollectionDirective >
      <Chart3DSeriesDirective dataSource={data} xName='x' name='Sales' yName='y' type='Column'>
      </Chart3DSeriesDirective>
    </Chart3DSeriesCollectionDirective>
  </Chart3DComponent>)
};
export default App;
createRoot(document.getElementById('charts')).render(<App />);

You can refer to our React 3D Charts feature tour page for its groundbreaking feature representations. You can also explore our React 3D Charts example that shows various 3D Chart types and how to represent time-dependent data, showing trends in data at equal intervals.