Flash3001 / iOSCharts.Xamarin

A Xamarin port by Lucas Teixeira for Charts (ios-charts) by Daniel Cohen Gindi, inspired by Philipp Jahoda
Other
68 stars 20 forks source link

Crashes on device, but works fine in Simulator #28

Closed daffodilistic closed 5 years ago

daffodilistic commented 7 years ago

Hi,

I have a Xamarin Forms project which uses iOSCharts, everything works fine in Simulator, but when I test the project on device, it crashes. I am using the LineChartView as a custom renderer with Xamarin.Forms, and I inherited iOSCharts.LineChartView as a parent class:

// Custom subclass
public class LineChartView : iOSCharts.LineChartView
{
    public void SetHorizontalLabels(string[] formattedTime, string displayFormat)
    {
        this.XAxis.ValueFormatter = new MonthFormatter(formattedTime, displayFormat);
    }
}

And here is my ViewRenderer:

public class LineChartViewRenderer : ViewRenderer<StockPortfolio.LineChartView, LineChartView>, IGenericChart
{
        LineChartView nativeChart;

    protected override void OnElementChanged(ElementChangedEventArgs<StockPortfolio.LineChartView> e)
    {
        base.OnElementChanged(e);

        nativeChart = new LineChartView(this.Context);
        Element.chart = this;

        SetNativeControl(nativeChart);
    }

    public void SetHorizontalLabels(string[] labels, string displayFormat)
    {
        nativeChart.SetHorizontalLabels(labels, displayFormat);
    }
}

Here's the stacktrace: https://pastebin.com/CpyBiFHS

Flash3001 commented 7 years ago

Hey @daffodilistic , this issue is the same as the one reported in here https://github.com/Flash3001/iOSCharts.Xamarin/issues/11 , but I wasn't able to fix it yet.

Flash3001 commented 5 years ago

It seems it is not possible to subclass a Swift class. (https://stackoverflow.com/a/35244676/1698917).

The current solution is to do what proposed on #11 comments.