How to change the data point selection color in Xamarin.Forms Charts?
Description:
ChartSelectionBehavior allows you to select any data point, that is, a segment in the series. This behavior highlights the particular segment inside the series. The selected segment color is not restricted to the default color in the Xamarin.Forms Charts.
Solution:
Essential chart for Xamarin.Forms provides data point selection and allows you to change the selected segment color for series. The SelectedDataPointColor property is used to define the custom color for the selected segment.
This property works only when you enable the EnableDataPointSelection property in series.
The following code example shows the selection feature for series segment.
XAML
<chart:SfChart.Series>
<chart:ColumnSeries ItemsSource="{Binding Data}"
EnableDataPointSelection="True" SelectedDataPointColor="#B399E6" />
</chart:SfChart.Series>
C#
ColumnSeries series = new ColumnSeries()
{
EnableDataPointSelection = true,
SelectedDataPointColor = Color.FromRgba(0.7, 0.6, 0.9, 1),
ItemsSource = GetData()
};
chart.Series.Add(series);
Output:
Conclusion
I hope you enjoyed learning about how to change the data point selection color in Xamarin.Forms Charts.
You can refer to our Xamarin.Forms Charts feature tour page to know about its other groundbreaking feature representations. You can also explore our Xamarin.Forms Charts documentation 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, Direct-Trac, or feedback portal. We are always happy to assist you!
Hello how deactvate the color change for the selected bar in the BarSeries chart type?
Hi Garbiele,
We are able to achieve your requirement to deactivate the color change for the selected bar by using below solutions.
Soloution 1 :
By tap the selected bar again.
Solution 2 :
Set the SelectedDataPointIndex = -1 via programmatically as per the below code snippet.
Code Snippet[C#]
series.SelectedDataPointIndex = -1;
Thanks,
Muneesh Kumar G.
is there a way to get only one colour to selected bar on sf chart series when we have more columns