This is a migrated thread and some comments may be shown as answers.

Get Color of Bar Chart Series From Selected Pie Chart Slice Color

3 Answers 127 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Angelo
Top achievements
Rank 1
Angelo asked on 01 Dec 2017, 01:11 PM
I would like to be able to create a bar chart dynamically and assign the color of the series based on the selected slice of the pie chart.  I am using the ChartSelectionBehavior_SelectionChanged event but I am not sure where to get the color of the pie slice from the ChartSelectionChangedEventArgs provided by the event.  I am using the Windows8 palette for my pie chart.

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 06 Dec 2017, 08:19 AM
Hello Angelo,

To get the color of the pie slice you can use the GetEntry() method of the Palette class. Then you can apply it via the DefaultVisualStyle property of the BarSeries. You can create the Style in code and apply it to the series. Or alternatively, you can use bindings instead of the SelectionChanged event. This way you can bind the ItemsSource of the BarSeries directly to the SelectedItems[0] of the RadPieChart. Also, you can use the SelectedItems in the DefaultVisualStyle and convert them to a color using IValueConverter. I prepared a small example showing this approach. Can you please give it a try and let me know how it goes? 

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Angelo
Top achievements
Rank 1
answered on 13 Dec 2017, 08:27 PM
I am getting a 'DataItem' is not accessible pm the xaml file.  Any thoughts?
0
Martin Ivanov
Telerik team
answered on 18 Dec 2017, 11:00 AM
Hello Angelo,

The only reason for this error that I can think of is if you are using very old version of UI for WPF. For example Q3 2011. If this is your case I would recommend you to test the solution if the latest version of UI for WPF. Otherwise, you can double check the referenced dlls and make sure that they are all of the same version. After this you can manually delete the "bin" and "obj" folders of the solution, and Clean/Rebuild it.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
ChartView
Asked by
Angelo
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Angelo
Top achievements
Rank 1
Share this question
or