How to change the legend position in React Chart?
This article explains how to change the legend position in React Chart.
Customize the legend position
You can change the position of the legend using the position property. By default, the legend position is set to auto, which is determined by the area type of the chart.
The position property includes the following options:
• Auto - Places the legend based on the area type.
• Top - Displays the legend at the top of the chart.
• Bottom - Displays the legend at the bottom of the chart.
• Right - Displays the legend at the right of the chart.
• Left - Displays the legend at the left of the chart.
• Custom - Displays the legend based on the given x and y values.
In the following code example, the legend can be positioned at the bottom by using the position property.
Index.js
import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, Inject,
AccumulationLegend, PieSeries, AccumulationDataLabel } from '@syncfusion/ej2-react-charts';
const Pie = () => {
return (
<accumulationchartcomponent id="pie-chart" title="Browser Market Share" legendsettings="{{" visible:="" true,="" position:="" 'bottom'="" }}="" center="{{" x:="" '50%',="" y:="" '50%'="" enableborderonmousemove="{false}">
<inject services="{[AccumulationLegend," pieseries,="" accumulationdatalabel]}="">
<accumulationseriescollectiondirective>
<accumulationseriesdirective datasource="{data1}" xname="x" yname="y" radius="{'70%'}">
</accumulationseriesdirective></accumulationseriescollectiondirective>
</inject></accumulationchartcomponent>
);
};
export default Pie;
const root = createRoot(document.getElementById('sample'));
root.render(<pie>);
The screenshots below display the results of the aforementioned code.
Screenshot: Legend docked at Bottom
Screenshot: Legend docked at Left
Screenshot: Legend docked at Top
Screenshot: Legend docked at Right
Screenshot: Legend docked at Custom
Conclusion
I hope you enjoyed learning how to change the legend position in React Chart.
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, Direct-Trac, or feedback portal. We are always happy to assist you!