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

Xamarin Pie graph coloring

1 Answer 107 Views
Chart
This is a migrated thread and some comments may be shown as answers.
jesus
Top achievements
Rank 1
jesus asked on 13 Jul 2016, 12:32 AM

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 :)

1 Answer, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 15 Jul 2016, 08:29 AM
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
Tags
Chart
Asked by
jesus
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or