Articles in this section
Category / Section

How to make a graph with multiple axes in React Chart?

3 mins read

This article explains how to make a graph with multiple axes in React Chart.

Customize the multiple axis

In addition to primaryXAxis and primaryYAxis, you can add n number of axis to the chart by using the axes property. Series can be associated with this axis, by mapping with axis’s unique name. It has been achieved by using the xAxisName and yAxisName properties of the series.

In the following code example, a secondary axis with the name yAxis1 is assigned to the series.

Index.js

import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { ChartComponent, SeriesCollectionDirective, AxesDirective, AxisDirective, SeriesDirective, Inject, Category, 
  SplineSeries } from '@syncfusion/ej2-react-charts';

const MultipleAxis = () => {
return (
   <ChartComponent id="charts">
     <Inject services={[Category, SplineSeries]} />
     <AxesDirective>
       <AxisDirective
         rowIndex={0}
         opposedPosition={true}
         minimum={20}
         maximum={36}
         interval={4}
         name="yAxis1"
         labelFormat="{value}"
       />
     </AxesDirective>
     <SeriesCollectionDirective>
       <SeriesDirective
         dataSource={data}
         xName="x"
         yName="y"
         width={2}
         type="Spline"
         name="Product A"
       />
       <SeriesDirective
         dataSource={data}
         xName="x"
         yName="y1"
         type="Spline"
         yAxisName="yAxis1"
         name="Product B"
         width={2}
       />
     </SeriesCollectionDirective>
   </ChartComponent>
   );
};
export default MultipleAxis;

const root = createRoot(document.getElementById('sample'));
root.render(<MultipleAxis />);

The following screenshot illustrate the output of the above code snippet.

Screenshot:

React chart multiple axis

View Sample in Stackblitz

Conclusion

I hope you enjoyed learning how to make a graph with multiple axes in React Chart Component.

You can refer to our React Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our React Chart example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied