Xamarin Pie graph coloring

2 posts, 0 answers
  1. jesus
    jesus avatar
    1 posts
    Member since:
    Apr 2011

    Posted 12 Jul 2016 Link to this post

    Hi everyone

    I need your help I added a dynamic pie chart ,

    but I want to change the color of the segments.

    I have followed examples but does not work .

    Here my code :


            private ObservableCollection<Models.CategoricalData> data1;

            public ObservableCollection<Models.CategoricalData> Data1
                    return data1;
                    if (data1 == value)
                    data1 = value;

    public override void OnNavigatedTo(NavigationParameters parameters)

    private async void LoadStatusVendingMachineCEDI()
                if (localDbService == null)

                var AllStatusVendingMachineCEDI = await localDbService.GetStatusVendingMachineCEDIAsync();

                if (AllStatusVendingMachineCEDI != null && AllStatusVendingMachineCEDI.Any())
                    StatusVendingMachineCEDI = new ObservableCollection<StatusVendingMachineCEDI>(AllStatusVendingMachineCEDI);

                    Data1 = new ObservableCollection<Models.CategoricalData>();

                    foreach (var r in StatusVendingMachineCEDI)
                        Data1.Add(new Models.CategoricalData { Category = r.StatusName, Value = r.AmountVendingMachines });





    and the XAMAL code:


                  <telerik:RadPieChart x:Name="chart">
                      <telerik:PieSeries ItemsSource="{Binding Data1}" ShowLabels="True">                    
                          <telerik:PropertyNameDataPointBinding PropertyName="Value"/>

    Any Sugestions??

    Thanks :)

  2. Ves
    Ves avatar
    2926 posts

    Posted 15 Jul 2016 Link to this post

    Hi Jesus,

    Looking at the code you have provided, it seems you are trying to bind the pie series ItemsSource to a property of the page itself. Bu default the BindingContext of the page is null, so the property Data1 will not be resolved. You need to ensure the page (or the chart) has correct BindingContext. You can find more information on databinding in this article.

    Once you have this working, you can create a custom palette for the chart in order to have the pie slices colored as per your requirements. Creating custom palette is described in this help topic.

    Best regards,
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top