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

4 posts, 0 answers
  1. Angelo
    Angelo avatar
    11 posts
    Member since:
    Nov 2017

    Posted 01 Dec 2017 Link to this post

    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.
  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    1493 posts

    Posted 06 Dec 2017 Link to this post

    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.
  3. Angelo
    Angelo avatar
    11 posts
    Member since:
    Nov 2017

    Posted 13 Dec 2017 in reply to Martin Ivanov Link to this post

    I am getting a 'DataItem' is not accessible pm the xaml file.  Any thoughts?
  4. Martin Ivanov
    Admin
    Martin Ivanov avatar
    1493 posts

    Posted 18 Dec 2017 Link to this post

    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.
Back to Top