Xamarin Pie graph coloring

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

    Posted 12 Jul 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
            {
                get
                {
                    return data1;
                }
                set
                {
                    if (data1 == value)
                    {
                        return;
                    }
                    data1 = value;
                    OnPropertyChanged();
                }
            }


    public override void OnNavigatedTo(NavigationParameters parameters)
            {
                LoadStatusVendingMachineCEDI();
            }

    private async void LoadStatusVendingMachineCEDI()
            {
                if (localDbService == null)
                {
                    return;
                }

                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:RadPieChart.Series>
                      <telerik:PieSeries ItemsSource="{Binding Data1}" ShowLabels="True">                    
                        <telerik:PieSeries.ValueBinding>
                          <telerik:PropertyNameDataPointBinding PropertyName="Value"/>
                        </telerik:PieSeries.ValueBinding>
                      </telerik:PieSeries>
                    </telerik:RadPieChart.Series>
                  </telerik:RadPieChart>
                </Grid>

    Any Sugestions??

    Thanks :)

  2. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 15 Jul 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,
    Ves
    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
  3. DevCraft banner
Back to Top