Articles in this section
Category / Section

How to replace the axis labels with image in Xamarin.Forms Chart?

1 min read

You can replace the Xamarin Chart axis labels with image using the LabelCreated event in ChartAxis and positioning the image using AbsoluteLayout.

 

The following code sample demonstrates how to replace the axis labels with image.

 

Xaml:

<AbsoluteLayout>
      <AbsoluteLayout x:Name="imageLayout" />
      <chart:SfChart x:Name="chart">
            <chart:SfChart.PrimaryAxis>
                 <chart:CategoryAxis x:Name="primaryAxis" 
                      LabelCreated="Handle_LabelCreated" />
            </chart:SfChart.PrimaryAxis>
            <chart:SfChart.SecondaryAxis>
                <chart:NumericalAxis x:Name="secondaryAxis" />
            </chart:SfChart.SecondaryAxis>
            <chart:SfChart.Series>
                <chart:ColumnSeries ItemsSource="{Binding SeriesData}" 
                     XBindingPath="XValue" YBindingPath="Value" />
            </chart:SfChart.Series>
     </chart:SfChart>
</AbsoluteLayout> 

 

C#:

void Handle_LabelCreated(object sender, ChartAxisLabelEventArgs e)
{
   ChartAxis axis = (sender as ChartAxis);
 
    if (axis is CategoryAxis)
    {
       double y = 615;
       double x = chart.ValueToPoint(axis, e.Position);
       Image image = new Image();
       for (int i = 0; i <= images.Count; i++)
       {
          if (i == e.Position)
          {  
             // Use the Images list property to set ImageSource value. 
            image.Source = Images[i];
            image.BackgroundColor = Color.Blue;
            break;
          }
       }
       imageLayout.Children.Add(image, new Rectangle(x - 15, y, 30, 30));
   }
} 

Output:

Images instead of axis labels in Xamarin.Forms Chart.

 

Conclusion

I hope you enjoyed learning about how to replace the axis labels with image in Xamarin.Forms Chart.

You can refer to our Xamarin Chart’s feature tour page to know about its other groundbreaking feature representations. You can also explore our Xamarin Chart Documentation to understand how to present and manipulate data.

 

For current customers, you can check out our Xamarin 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  Xamarin Chart and other Xamarin components.

 

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac 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
Please  to leave a comment
Access denied
Access denied