How to group stacking series in the React Chart?
This article provides an explanation of how to group stacking series in the React Chart.
Customize the grouped stacking column
You can utilize the stackingGroup property to group stacked columns, 100% stacked columns, stacked bar and 100% stacked bar. Columns with the same group name are stacked on top of each other.
In the following code example, the first and third series are grouped together and second and fourth series are grouped together.
Index.js
import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, StackingColumnSeries,
Tooltip, Highlight, ColumnSeries } from '@syncfusion/ej2-react-charts';
const StackedColumn = () => {
const axisLabelRender = (args) => {
args.text = args.text.replace('0000000', '0M').replace('000000', 'M');
};
return (
<ChartComponent
id="charts"
legendSettings={{ enableHighlight: true }}
primaryXAxis={{
interval: 1,
labelIntersectAction: 'Rotate45',
valueType: 'Category'
}}
primaryYAxis={{
title: 'Vehicles Production (In Millions)',
labelFormat: '{value}'
}}
title="Motor Vehicle Production by Manufacturer"
tooltip={{ enable: true }}
axisLabelRender={axisLabelRender.bind(this)}
>
<Inject
services={[ StackingColumnSeries, Category, Legend, Tooltip, Highlight, ColumnSeries ]}
/>
<SeriesCollectionDirective>
<SeriesDirective
dataSource={data1}
xName="x"
yName="y"
name="General Motors"
type="StackingColumn"
stackingGroup="GroupA"
/>
<SeriesDirective
dataSource={data2}
xName="x"
yName="y"
name="Honda"
type="StackingColumn"
stackingGroup="GroupB"
/>
<SeriesDirective
dataSource={data3}
xName="x"
yName="y"
name="Suzuki"
type="StackingColumn"
stackingGroup="GroupA"
/>
<SeriesDirective
dataSource={data4}
xName="x"
yName="y"
name="BMW"
type="StackingColumn"
stackingGroup="GroupB"
/>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default StackedColumn;
const root = createRoot(document.getElementById('sample'));
root.render(<StackedColumn />);
The following screenshot illustrate the output of the above code snippet.
Screenshot:
Before grouping the Stacked Columns | After grouping the Stacked Columns |
---|---|
Conclusion
I hope you enjoyed learning how to group stacking series in the 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!