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

BarChartView is just crashing on device #12

Closed Chico741 closed 7 years ago

Chico741 commented 8 years ago

I implemented a BarChartView which is crashing just on device. In my case on an iPhone6 with iOS 10.1. On simulator everything is running fine.

Could be the same issue like #11 ?

Native stacktrace:
critical:   0   libmonosgen-2.0.dylib               0x00000001006f3d0c mono_handle_native_sigsegv + 260
critical:   1   libmonosgen-2.0.dylib               0x00000001006ff214 mono_sigsegv_signal_handler + 336
critical:   2   libsystem_platform.dylib            0x00000001928b0348 _sigtramp + 52
critical:   3   Charts                              0x00000001002f3438 _TFC6Charts13ChartViewBasecfT5frameVSC6CGRect_S0_ + 896
critical:   4   Charts                              0x00000001002ccb9c _TFC6Charts20BarLineChartViewBasecfT5frameVSC6CGRect_S0_ + 668
critical:   5   Charts                              0x000000010034e49c _TToFC6Charts12BarChartViewcfT5frameVSC6CGRect_S0_ + 84
critical:   6   libiOSCharts.dll.dylib              0x000000010566a4a4 wrapper_managed_to_native_ApiDefinition_Messaging_IntPtr_objc_msgSendSuper_intptr_intptr + 212
critical:   7   libiOSCharts.dll.dylib              0x00000001054f1da8 iOSCharts_BarChartView__ctor + 632
critical:   8   libCustom.iOS.exe.dylib             0x0000000100ab4220 Custom_Views_Components_Charts_CustomBarChartView__ctor + 144
critical:   9   libCustom.iOS.exe.dylib             0x0000000100ab1db4 Custom_Views_CommunityStatisticView__ctor + 116
critical:   10  libCustom.iOS.exe.dylib             0x0000000100aad32c Custom_Views_CommunityWeekView__ctor + 60
critical:   11  libCustom.iOS.exe.dylib             0x0000000100a2f068 Custom_Views_CommunityView__ctor + 200
Flash3001 commented 8 years ago

@Chico741 I'm still looking at #11 , but they might be related as both only happens when you inherit from those classes.

Could you provide the code for this crash?

Chico741 commented 8 years ago

Thanks very much for your effort, please find the code below.

public class CustomBarChartView : BarChartView
{
    public CustomBarChartView()
    {
        CustomBarChartDataSet providedDataSet = new CustomBarChartDataSet(new List<BarChartDataEntry> { new BarChartDataEntry(0, 89) }.ToArray(), "Provided");
        providedDataSet.TintColor = ColorsHelperIOS.Blue;

        CustomBarChartDataSet dummyDataSet = new CustomBarChartDataSet(new List<BarChartDataEntry> { new BarChartDataEntry(1, 10) }.ToArray(), "Dummy");
        dummyDataSet.TintColor = UIColor.Clear;

        CustomBarChartDataSet soldDataSet = new CustomBarChartDataSet(new List<BarChartDataEntry> { new BarChartDataEntry(2, 23) }.ToArray(), "Sold");
        soldDataSet.TintColor = ColorsHelperIOS.Green;

        BarChartData barData = new BarChartData(new List<BarChartDataSet> { providedDataSet, dummyDataSet, soldDataSet }.ToArray());
        Data = barData;
        HighlightPerTapEnabled = false;
        Legend.Enabled = false;
        DescriptionText = "";
        LeftAxis.Enabled = false;
        RightAxis.Enabled = false;
        XAxis.Enabled = false;
        DoubleTapToZoomEnabled = false;
        PinchZoomEnabled = false;
        UserInteractionEnabled = false;
        nfloat sideOffset = 55;
        SetViewPortOffsetsWithLeft(sideOffset, 20, sideOffset, 0);
    }
}

public class CustomBarChartDataSet : BarChartDataSet
{
    private UIColor _tintColor;
    public UIColor TintColor {
        get {
            return _tintColor;
        }

        set {
            _tintColor = value;
            ValueTextColor = _tintColor;
            BarBorderColor = _tintColor;
        }
    }

    public CustomBarChartDataSet(BarChartDataEntry[] values, string label) : base(values, label)
    {
        ValueFormatter = new ValueFormatter();
        ValueFont = FontsHelperIOS.SemiBold(17);
        BarBorderWidth = 1.5f;
        HighlightEnabled = false;
        SetColor(UIColor.Clear);
    }
}

public class ValueFormatter : InterfaceChartValueFormatter
{
    public override string Entry(double value, ChartDataEntry entry, nint dataSetIndex, ChartViewPortHandler viewPortHandler)
    {
        return string.Format(LocalizationHelper.GetLocalizedString("community_value_format"), value);
    }
}
Chico741 commented 8 years ago

@Flash3001 do you have any news regarding this issues?

Flash3001 commented 8 years ago

@Chico741 I wasn't able to figure out yet what is causing this crash on device when any of those classes (BarChartView or ChartMarkerImage) are inherited.

In both cases you aren't changing those classes behavior, only setting public properties, you can use the default BarChartView and set the values outside the constructor.

In the case for #11 the image doesn't change based on the entry, so you can set it on the public property on the basic ChartMarkerImage.

Please, tell me if changing this design will work for you. Meanwhile I'll keep trying to find the root cause for the problem.

Chico741 commented 8 years ago

@Flash3001 you are right without subclassing everything is working fine. thanks for your help!

flashfoxter commented 7 years ago

Same issue, but i need to inherit ChartMarkerView