How can I help you?
Getting Started with React Charts of Syncfusion
18 May 202613 minutes to read
This section describes the steps to create a simple Chart and demonstrates the basic usage of the Chart component.
Ready to streamline your Syncfusion® React development? Discover the full potential of Syncfusion® React components with Syncfusion® AI Coding Assistant. Effortlessly integrate, configure, and enhance your projects with intelligent, context-aware code suggestions, streamlined setups, and real-time insights—all seamlessly integrated into your preferred AI-powered IDEs like VS Code, Cursor, Syncfusion® CodeStudio and more. Explore Syncfusion® AI Coding Assistant
A quick video overview of the React Charts setup is available:
Dependencies
Below is the list of minimum dependencies required to use the 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-appinstead, refer to this documentation for more details.
To create a new React application, run the following command.
npm create vite@latest my-appThis command will prompt you for a few settings for the new project, such as selecting a framework and a variant.

Otherwise, you can directly set up our project with TypeScript or JavaScript environment based on the following commands
To set up a React application in TypeScript environment:
npm create vite@latest my-app -- --template react-tsTo set up a React application in JavaScript environment:
npm create vite@latest my-app -- --template reactTo navigate and run your project:
cd my-app
npm run devInstall Syncfusion® Chart package
All the available Essential® JS 2 packages are published in the npmjs.com public registry.
To install the Syncfusion® Chart package, use the following command
npm install @syncfusion/ej2-react-charts --saveThe –save will instruct NPM to include the Chart package inside of the dependencies section of the package.json.
Add Chart to the project
Add the Chart component to src/App.tsx using the following code.
import { ChartComponent } from '@syncfusion/ej2-react-charts';
import * as React from 'react';
function App() {
return (<ChartComponent />);
}
export default App;import { ChartComponent } from '@syncfusion/ej2-react-charts';
import * as React from 'react';
function App() {
return (<ChartComponent />);
}
export default App;Note: This will render an empty chart area. Proceed to the next steps to add data, series, and necessary module injections to visualize your data.
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 Chart using React 18, where the createRoot API is used for rendering the component.
import { ChartComponent } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
function App() {
return <ChartComponent id='charts'/>;
}
export default App;
// Root should point to a container div in index.html (e.g., <div id="root"></div>)
const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(<App />);import { ChartComponent } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
function App() {
return <ChartComponent id='charts' />
}
export default App;
// Root should point to a container div in index.html (e.g., <div id="root"></div>)
const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(<App />);Module injection
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 Chart component. In the current application, we are going to modify the above basic Chart to visualize sales data for a particular year. For this application we are going to use line series and category axis feature of the Chart. Please find the relevant feature service name and description as follows.
-
LineSeries- Inject this module in toservicesto use line series. -
Category- Inject this module in toservicesto use category feature.
Import the above-mentioned modules from the Chart package and inject them into the services section of the Chart component as follows.
import { ChartComponent, LineSeries, Category, Inject } from '@syncfusion/ej2-react-charts';
import * as React from "react";
function App() {
return <ChartComponent>
<Inject services={[LineSeries, Category]}/>
</ChartComponent>;
}
export default App;import { ChartComponent, LineSeries, Category, Inject } from '@syncfusion/ej2-react-charts';
import * as React from "react";
function App() {
return <ChartComponent>
<Inject services={[LineSeries, Category]}/>
</ChartComponent>;
}
export default App;Populate Chart with data
This section explains how to plot the following JSON data to the Chart.
export let data = [
{ month: 'Jan', sales: 35 }, { month: 'Feb', sales: 28 },
{ month: 'Mar', sales: 34 }, { month: 'Apr', sales: 32 },
{ month: 'May', sales: 40 }, { month: 'Jun', sales: 32 },
{ month: 'Jul', sales: 35 }, { month: 'Aug', sales: 55 },
{ month: 'Sep', sales: 38 }, { month: 'Oct', sales: 30 },
{ month: 'Nov', sales: 25 }, { month: 'Dec', sales: 32 }
];export let data: Object[] = [
{ month: 'Jan', sales: 35 }, { month: 'Feb', sales: 28 },
{ month: 'Mar', sales: 34 }, { month: 'Apr', sales: 32 },
{ month: 'May', sales: 40 }, { month: 'Jun', sales: 32 },
{ month: 'Jul', sales: 35 }, { month: 'Aug', sales: 55 },
{ month: 'Sep', sales: 38 }, { month: 'Oct', sales: 30 },
{ month: 'Nov', sales: 25 }, { month: 'Dec', sales: 32 }
];Add series to the Chart using the <SeriesCollectionDirective> and <SeriesDirective> components. Map the JSON fields month and sales 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 { Category, ChartComponent, Inject, LineSeries, SeriesCollectionDirective, SeriesDirective } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';
import { data } from './datasource';
function App() {
return <ChartComponent id="charts" primaryXAxis={{ valueType: 'Category' }}>
<Inject services={[LineSeries, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='month' yName='sales' name='Sales' type='Line'/>
</SeriesCollectionDirective>
</ChartComponent>
}
export default App;
const root = createRoot(document.getElementById('charts'));
root.render(<App />);import { Category, ChartComponent, Inject, LineSeries, SeriesCollectionDirective, SeriesDirective } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import { createRoot } from 'react-dom/client';
import { data } from './datasource';
function App() {
return <ChartComponent id="charts" primaryXAxis={{ valueType: 'Category' }}>
<Inject services={[LineSeries, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='month' yName='sales' name='Sales' type='Line'/>
</SeriesCollectionDirective>
</ChartComponent>
}
export default App;
const root = createRoot(document.getElementById('charts'));
root.render(<App />);export let data = [
{ month: 'Jan', sales: 35 }, { month: 'Feb', sales: 28 },
{ month: 'Mar', sales: 34 }, { month: 'Apr', sales: 32 },
{ month: 'May', sales: 40 }, { month: 'Jun', sales: 32 },
{ month: 'Jul', sales: 35 }, { month: 'Aug', sales: 55 },
{ month: 'Sep', sales: 38 }, { month: 'Oct', sales: 30 },
{ month: 'Nov', sales: 25 }, { month: 'Dec', sales: 32 }
];export let data: Object[] = [
{ month: 'Jan', sales: 35 }, { month: 'Feb', sales: 28 },
{ month: 'Mar', sales: 34 }, { month: 'Apr', sales: 32 },
{ month: 'May', sales: 40 }, { month: 'Jun', sales: 32 },
{ month: 'Jul', sales: 35 }, { month: 'Aug', sales: 55 },
{ month: 'Sep', sales: 38 }, { month: 'Oct', sales: 30 },
{ month: 'Nov', sales: 25 }, { month: 'Dec', sales: 32 }
];You can refer to our React Charts feature tour page for its groundbreaking feature representations. You can also explore our React Charts example that shows various Chart types and how to represent time-dependent data, showing trends in data at equal intervals.