How to make a graph with multiple axes in React Chart?
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 axes to the chart by using the axes property. Series can be associated with these axes by mapping them with the axes’ unique names. This can be 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}">
</axisdirective></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}">
</seriesdirective></seriesdirective></seriescollectiondirective>
</inject></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:
Refer to the working sample for additional details and implementation: View Sample in Stackblitz
Conclusion
We 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, BoldDesk Support, or feedback portal. We are always happy to assist you!