Articles in this section
Category / Section

How to customize the data marker of charts in Xamarin.Android

1 min read

The data markers are used to provide information about the data points to the user. By enabling the ShowLabel, you can display the Y value.

 

[C#] PieSeries added to the SfChart

 

SfChart chart = new SfChart();
 
PieSeries pieSeries = new PieSeries()
{
 
    DataSource = Data,
    DataMarker.ShowLabel = true,
   …
};
 
pieSeries.DataMarkerLabelCreated += PieSeries _DataMarkerLabelCreated;
 
..
chart.Series.Add(pieSeries);

 

This article explains how to display both X and Y value on the data marker with the following solutions.

 

The data marker label is entirely customizable using the DataMarkerLabelCreated event.

 

Solution 1:

 

Setting the Label property of DataMarkerLabel from the DataMarkerLabelCreated event as shown in the following code sample.

 

[C#] Setting the default label text – Y value with X value from the specific indexed data point

 

 
private void PieSeries _DataMarkerLabelCreated(object sender, ChartSeries.DataMarkerLabelCreatedEventArgs e)
{ 
            e.DataMarkerLabel.Label = (DataSource[e.DataMarkerLabel.Index] as DataPoint).XValue + " : " + e.DataMarkerLabel.Label;
}
 

 

Solution 2:

 

The entire view of the data marker has been customized by using the View property of DataMarkerLabel from the DataMarkerLabelCreated event as shown in the following code sample.

 

[C#] Setting the desired view to show the needed information

 

 
private void PieSeries _DataMarkerLabelCreated(object sender, ChartSeries.DataMarkerLabelCreatedEventArgs e)
{ 
            LinearLayout layout = new LinearLayout(chart.Context);
            layout.SetBackgroundColor(Color.ParseColor("#00BDAE"));
            layout.SetPadding(3, 3, 3, 3);
 
            TextView text = new TextView(chart.Context);
            text.Text (DataSource[e.DataMarkerLabel.Index] as DataPoint).XValue + " : " + e.DataMarkerLabel.Label);
            text.SetTextColor(Color.White);
 
            layout.AddView(text);
            e.DataMarkerLabel.View = layout;
 }
 

 

 

SfChart data marker label customization

 

 

See Also

 

How to add multiple trackballs in Xamarin.Android Chart

 

How to export the chart to PDF in Xamarin.Android

 

How to zoom the chart to pinch gesture orientation

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied