Search code examples
xamarin.iosxamarinshinobi

ShinobiCharts throws CALayerInvalidGeometry error


I'm running into troubles trying to create a Donut chart on the Shinobi for iOS using Xamarin.iOS.

The code that I'm using to setup the chart is the following:

private void SetupSChart(){
            float margin = 0;

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) {
                margin = 10;
            } else {
                margin = 50;
            }
            var frame = UIScreen.MainScreen.Bounds;//new RectangleF (margin, margin, View.Bounds.Width - 2 * margin, View.Bounds.Height - 2 * margin);
            m_schart = new ShinobiChart (frame){ 
                Title = "Poll replies / answer",
                AutoresizingMask = UIViewAutoresizing.None
            };

            View.AddSubview (m_schart);
            m_schart.DataSource = new ChartDataSource(this.Poll);
            m_schart.Legend.Hidden = false;
        }

Then, I get the following exception:

CALayerInvalidGeometry

Objective-C exception thrown.  Name: CALayerInvalidGeometry Reason: CALayer position contains NaN: [nan nan]

CALayer position contains NaN: [nan nan]

What am I doing wrong?

Thanks


Solution

  • We've already chatted via our regular support channel, but I thought I'd respond here as well to help anyone else who is experiencing similar issues.

    The crash you're seeing in the donut chart occurs when all of the slices have a value of 0. The chart doesn't currently handle this in a nice way - we've raised an issue in our product backlog to deal with this better.

    In the meantime, the best approach would be to hide the series if all the data points in the series have zero value. You can do this in the chart datasource, in the GetSeries method. The crash occurs when the chart tries to draw the series, so if you hide the series before it is drawn, you can avoid this issue.

    Many thanks,

    Dan