Doughut chart CenterView results in exception

Creating a simple doughnut series and can display the graph correctly.      Decided that the Centerview would be something that I could use.   Added the additional line of code to display a simple label in the centerview.    Results in a Java Null pointer exception.


            DoughnutSeries doughnutSeries = new DoughnutSeries()
            {
                ItemsSource = Data1,
                XBindingPath = "Item",
                YBindingPath = "Value",
                DoughnutCoefficient = 0.6,
                ExplodeAll = true,
                DataMarkerPosition = CircularSeriesDataMarkerPosition.Inside                
                
        };


//This line which is intended to show a label in the center of the doughnutseries

              doughnutSeries.CenterView = new Label() { Text = "CenterView" };

ACTUAL RESULT
Java.Lang.NullPointerException
  Message=Attempt to read from field 'int android.view.ViewGroup$LayoutParams.width' on a null object reference

EXPECTED RESULT
Display a label with Text "CenterView" in the center of the doughnut graph.


1 Reply

DD Devakumar Dhanapoosanam Syncfusion Team February 24, 2020 09:01 AM UTC

Hi Spotty, 
 
Greetings from Syncfusion. 
 
We would like to let you know that the reported crash issue while adding view directly to the template with XF version 4.3.0.991221 is a framework level issue and a known issue.  
 
Regarding this, we have already reported this case to the Xamarin team, please refer to the following link for further follow-up,  
  
 
You can resolve this issue by adding the Label inside any parent layout(like StackLayout, Grid) as per in below code snippet   
 
XAML: 
<chart:DoughnutSeries.CenterView> 
          <StackLayout> 
                  <Label Text="CenterView "/> 
          </StackLayout> 
</chart:DoughnutSeries.CenterView> 
 
C#: 
StackLayout stackLayout = new StackLayout(); 
stackLayout.Children.Add(new Label() { Text = "CenterView" }); 
doughnutSeries.CenterView = stackLayout; 
 
Note: The Xamarin team has fixed the issue and we are currently requesting them to get the correct timeline to move that fix.

 
Please let us know if you need any further assistance on this. 
 
Regards, 
Devakumar D 


Loader.
Up arrow icon