Articles in this section
Category / Section

How to display the modified axis labels in React Chart?

4 mins read

This article explains how to display the modified axis labels in the React Chart.

Customize the axis labels

Axis labels in the chart are generated based on the provided data points. In cases where you need to customize the UI by replacing the automatically generated labels with your desired text, you can achieve this by modifying the content in the axisLabelRender event at the desired index.

In the following code example, the primary y-axis labels are changed using the event.

Index.js

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

const Line = () => {
 const axisLabelRender = (args) => {
   if (args.axis.orientation === 'Vertical') 
   {
     if (args.value === 1.6) {
       args.text = 'Low';
     } else if (args.value === 2.1000000000000005) {
       args.text = 'Average';
     } else if (args.value === 2.6) {
       args.text = 'High';
     }
   }
 }
 return (
       <ChartComponent
         id="charts"
         primaryXAxis={{
           valueType: 'Category',
           labelPlacement: 'OnTicks',
           interval: 2
         }}
         primaryYAxis={{
           minimum: 1.6,
           maximum: 2.6,
           interval: 0.1
         }}
         title="USA Wheat Production"
         axisLabelRender={axisLabelRender.bind(this)}
       >
         <Inject
           services={[LineSeries, Tooltip, Category]}
         />
         <SeriesCollectionDirective>
           <SeriesDirective
             dataSource={data}
             xName="x"
             yName="y"
             marker={{
               visible: true,
               isFilled: true
             }}
             type="Line"
           ></SeriesDirective>
         </SeriesCollectionDirective>
       </ChartComponent>
   );
};
export default Line;

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

The following screenshot illustrate the output of the above code snippet.

Screenshot:

React chart modified axis label

View Sample in Stackblitz

Conclusion

I hope you enjoyed learning how to display the modified axis labels 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!

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