SwiftUICharts icon indicating copy to clipboard operation
SwiftUICharts copied to clipboard

LineChart error when all data points have same value

Open mvolkmann opened this issue 3 years ago • 1 comments

When all my data points have the same value, I get an error from LineChart. Changing one of the values to zero makes the error go away. I wonder if this happens because it cannot calculate the y-axis range to use. I'd like to try setting the minimum value of the y-axis to zero to see if that makes the error go away. How can I do that?

Here is the error I get:

Thread 1: "CALayer position contains NaN: [nan nan]. Layer: <_TtC7SwiftUIP33_F176A6CF4451B27508D54E2BEAEBFD5415ColorShapeLayer:0x2837896c0; position = CGPoint (59 334); bounds = CGRect (0 0; 0 0); delegate = <_TtC7SwiftUIP33_A34643117F00277B93DEBAB70EC0697122_UIShapeHitTestingView: 0x11dfc1570; frame = (59 334; 0 0); anchorPoint = (0, 0); autoresizesSubviews = NO; layer = <_TtC7SwiftUIP33_F176A6CF4451B27508D54E2BEAEBFD5415ColorShapeLayer: 0x2837896c0>>; allowsEdgeAntialiasing = YES; allowsGroupOpacity = YES; anchorPoint = CGPoint (0 0); strokeEnd = 1; path = <CGPath 0x2805bcfc0>; _swiftUI_displayListID = 310; lineDashPattern = (\n); lineWidth = 3; strokeColor = <CGColor 0x2813c57a0> [<CGColorSpace 0x2813f71e0> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1; extended range)] ( 0 0 0 1 ); fillColor = <CGColor 0x2813a3060> [<CGColorSpace 0x2813f71e0> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1; extended range)] ( 0 0 0 0 ); animations = []>"

mvolkmann avatar Jul 18 '22 18:07 mvolkmann

I bumped into this too. In my case, it was related to the LineChartStyle and specifically when the baseline and the topline were the same, the CALayer error occurs. In my case, I had the following as part of the chartStyle...

                                    baseline            : .minimumWithMaximum(of: smallestValue),
                                    topLine             : .maximum(of: largestvalue),

To work around the problem, I just ensure that "largestvalue" and "smallestValue" are not ever the same (If the are, I just added one to largestvalue)

brentkevern avatar Jul 26 '22 18:07 brentkevern