Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LineChart error when all data points have same value #215

Open
mvolkmann opened this issue Jul 18, 2022 · 1 comment
Open

LineChart error when all data points have same value #215

mvolkmann opened this issue Jul 18, 2022 · 1 comment

Comments

@mvolkmann
Copy link

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 = []>"
@brentkevern
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants