How to apply custom fonts for legend in React Chart?
This article explains how to customize the legend font in React Chart.
Customize the font of legend
You can set a custom font family to all the text elements in the chart. You can easily customize the legend font by using the fontFamily, fontWeight, fontStyle, size, and color properties within the textStyle property of the legend.
In the following code example, the legend font is customized by using the fontStyle, fontWeight, and color properties.
Index.js
import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, ColumnSeries,
Highlight, DataLabel } from '@syncfusion/ej2-react-charts';
const Column = () => {
return (
<ChartComponent
id="charts"
legendSettings={{
visible: true,
position: 'Top',
enableHighlight: true,
textStyle: {
fontStyle: 'Italic',
fontWeight: '800',
color: 'blue'
}
}}
primaryXAxis={{
valueType: 'Category',
interval: 1,
title: 'Country'
}}
primaryYAxis={{
title: 'Medal Count',
maximum: 50,
interval: 10
}}
tooltip={{
enable: true,
header: '<b>${point.tooltip}</b>',
shared: true
}}
title="Olympic Medal Counts - RIO"
titleStyle={{
position: 'Top',
size: '16px',
fontStyle: 'Arial',
fontWeight: '700'
}}
>
<Inject
services={[ColumnSeries, Legend, Category, Highlight, DataLabel]}
/>
<SeriesCollectionDirective>
<SeriesDirective
dataSource={data1}
xName="x"
yName="y"
name="Gold"
type="Column"
columnWidth={0.8}
marker={{
dataLabel: {
visible: true,
fill: '#1AC9E6',
rx: 0,
ry: 0,
position: 'Outer'
}
}}
/>
<SeriesDirective
dataSource={data2}
xName="x"
yName="y"
name="Silver"
type="Column"
columnWidth={0.8}
marker={{
dataLabel: {
visible: true,
fill: '#DA4CB2',
rx: 0,
ry: 0,
position: 'Outer'
}
}}
/>
<SeriesDirective
dataSource={data3}
xName="x"
yName="y"
name="Bronze"
type="Column"
columnWidth={0.8}
marker={{
dataLabel: {
visible: true,
fill: '#EDBB40',
rx: 0,
ry: 0,
position: 'Outer'
}
}}
/>
</SeriesCollectionDirective>
</ChartComponent>
</div>
</div>
);
};
export default Column;
const root = createRoot(document.getElementById('sample'));
root.render(<Column />);
The following screenshot illustrates the output of the above code snippet.
Screenshot:
Conclusion
I hope you enjoyed learning how to customize the legend font 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!