How to Add Images to Each Data Point in Angular Chart Component?
This article demonstrates how to add custom images to individual data points in the Angular Chart component. This approach is useful when you want to visually represent different states or categories using icons or images instead of standard shapes.
To achieve this, you need to:
- Set the shape property in MarkerSettingsModel to “Image” to use images as markers.
- Use the pointRender event in the chart to dynamically assign different images to each data point based on its index, using the args.point.marker.imageUrl property.
Code Example
app.component.html
<ejs-chart
(pointRender)="pointRender($event)"
>
<e-series-collection>
<e-series
[dataSource]="data"
type="Line"
xName="Period"
yName="Banana_ProductionRate"
width="2"
[marker]="marker"
opacity="1"
>
</e-series>
</e-series-collection>
</ejs-chart>
app.component.ts
//Initializing Marker
public marker: Object = {
visible: true,
shape: 'Image',
imageUrl: './assets/sad.png',
width: 40,
height: 40,
};
public width: string = Browser.isDevice ? '100%' : '75%';
public pointRender = (args: IPointEventArgs) => {
if(args.point.index === 0) {
args.point.marker.imageUrl = './assets/happy.png';
}
else if(args.point.index === 1) {
args.point.marker.imageUrl = './assets/neutral.png';
}
else if(args.point.index === 2) {
args.point.marker.imageUrl = './assets/sad.png';
}
}
Output
Sample
Conclusion
I hope you enjoyed learning about how to add images to each data point in Angular Chart component.
You can refer to our Angular Chart’s feature tour page to learn about its other groundbreaking feature representations. You can also explore our Angular Chart Documentation to understand how to present and manipulate data.
For current customers, you can check out our Angular components on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to explore our Angular Chart and other Angular components.
If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our support forums, Direct-Trac or feedback portal, or the feedback portal. We are always happy to assist you!