Articles in this section
Category / Section

How to customize the title of React Chart?

5 mins read

This article explains how to customize the title of the React Chart.

Customize the title

A chart can be given a title using the title property to display information about the plotted data.

The titleStyle property of chart title provides options to customize the size, color, font family, font weight, font style, opacity, text alignment and text overflow.

Alignment changes

You can align the title to the near, far, or center of the chart by using the textAlignment property.

In the following code example, the chart title is aligned to the far.

Index.js

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

const Line = () => {
return (
   <ChartComponent
     id="charts"
     primaryXAxis={{
       valueType: 'Category',
       interval: 1
     }}
     primaryYAxis={{
       minimum: 0,
       maximum: 100000,
       interval: 10000,
       labelFormat: '{value}'
     }}
     title="Monthly Revenue"
     titleStyle={{
       textAlignment: 'Far',
       color: 'blue',
       fontFamily: 'Italic',
       size: '20px',
       fontWeight: '600'
     }}
   >
     <Inject services={[LineSeries, Category]} />
     <SeriesCollectionDirective>
       <SeriesDirective
         dataSource={chartData}
         xName="x"
         yName="y"
         width={2}
         type="Line"
         fill="Blue"
       />
     </SeriesCollectionDirective>
   </ChartComponent>
  );
};
export default Line;

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

The following screenshot portrays the results of the code snippet mentioned above.

Screenshot:

React chart title alignment

Customization

It supports changing its border color, border width, and background by using properties such as border and background.

In the following code example, the chart title is customized with border, background.

Index.js

   <ChartComponent
     id="charts"      
     title="Monthly Revenue"
     titleStyle={{
       background: 'skyblue',
       border: {
         color: 'violet',
         width: 4
       }
     }}
   >
     <Inject services={[LineSeries, Category]} />
     <SeriesCollectionDirective>
       <SeriesDirective
         dataSource={chartData}
         xName="x"
         yName="y"
         width={2}
         type="Line"
       />
     </SeriesCollectionDirective>
  </ChartComponent>

The following screenshot portrays the results of the code snippet mentioned above.

Screenshot:

React chart title customization

Multi-line title

You can create multi-line chart titles using the textOverflow property. By default, the chart title wraps.

Screenshot:

React chart title wrap

View Sample in Stackblitz

Conclusion

I hope you enjoyed learning how to customize the title of 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!

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