How to replace the axis labels with image in React Chart?
This article explains how to replace the axis labels with image in the React Chart.
Customize the axis labels with image
Annotations are used to mark the specific area of interest in the chart area with texts, shapes or images.
You can replace the axis labels with image by using the annotations option. By using the content option of annotation object, you can specify the class of the element that needs to be displayed in the chart area.
In the following code example, the primary x axis labels are replaced with an image.
Index.js
import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Category, ColumnSeries,
ChartAnnotation, AnnotationsDirective, AnnotationDirective } from '@syncfusion/ej2-react-charts';
const Column = () => {
return (
<ChartComponent
id="charts"
primaryXAxis={{
valueType: 'Category',
interval: 1,
labelPlacement: 'OnTicks',
labelPosition: 'Inside'
}}
primaryYAxis={{
minimum: 0,
maximum: 80,
interval: 10
}}
>
<Inject services={[ColumnSeries, Category, ChartAnnotation]} />
<AnnotationsDirective>
<AnnotationDirective
content='<div class="fa fa-bicycle" style="font-size:22px;color:blue"></div>'
x="Sedan"
y={3}
coordinateUnits="Point"
></AnnotationDirective>
<AnnotationDirective
content='<div class="fa fa-car" style="font-size:20px;color:blue"></div>'
x="MUV"
y={3}
coordinateUnits="Point"
></AnnotationDirective>
<AnnotationDirective
content='<div class="fa fa-bus" style="font-size:20px;color:blue"></div>'
x="Hatchback"
y={3}
coordinateUnits="Point"
></AnnotationDirective>
<AnnotationDirective
content='<div class="fa fa-train" style="font-size:20px;color:blue"></div>'
x="SUV"
y={3}
coordinateUnits="Point"
></AnnotationDirective>
<AnnotationDirective
content='<div class="fa fa-ship" style="font-size:20px;color:blue"></div>'
x="Coupe"
y={3}
coordinateUnits="Point"
></AnnotationDirective>
</AnnotationsDirective>
<SeriesCollectionDirective>
<SeriesDirective
dataSource={data}
xName="x"
yName="y"
fill="#febe17"
type="Column"
/>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default Column;
const root = createRoot(document.getElementById('sample'));
root.render(<Column />);
The following screenshot portrays the results of the code snippet mentioned above.
Screenshot:
Conclusion
I hope you enjoyed learning how to replace the axis labels with image 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!