We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to change the data point selection color?

Platform: Xamarin.Forms |
Control: SfChart |
Published Date: May 23, 2015 |
Last Revised Date: June 25, 2019

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.

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.

 

Note:

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:

Column chart segment is selected in Xamarin.Forms

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
John Rennemeyer
Dec 07, 2015
Is there a way to disable the selection color? In our case, we are using a PieSeries which explodes the selected item when tapped. We want the explode to occur, but not the color change. When we do not specify a SelectedDataPointColor, it defaults to some grayish color. Reply
Karthikeyan V [Syncfusion]
Dec 08, 2015
Hi John, We have analyzed your requirement. You can achieve your requirement with help of SelectionChanging event in chart. Please refer the below code example. Code Example: Chart.SelectionChanging += (object sender, ChartSelectionChangingEventArgs e) => { e.Cancel = true;// To avoid the selection color (e.SelectedSeries as PieSeries).ExplodeIndex = e.SelectedDataPointIndex; }; Regards, Karthikeyan V.
Gabriele
Sep 14, 2017

Hello how deactvate the color change for the selected bar in the BarSeries chart type?

Reply
Muneesh Kumar G [Syncfusion]
Sep 15, 2017

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.

Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon