-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Crash building iterator. Range requires lowerBound <= upperBound #4798
Comments
This can happen when max values are 0 or negative values. make sure the x values are not 0 or negative in the data entry x value array you add to the Chart Data entry. you can add a guard let to check if the max > min then proceed with make iterator as a temporary solution |
hello @k1ran-ak, I just checked and I don't have any negative value in my data :
Tried to swap min and max before building iterator if min > max and I got the chart display without a crash but when I scroll to the very end of it, the line disappear. |
Found a quick fix (available in above pull request) that is not perfect and doesn't solve the source of the issue but at least it doesn't crash anymore |
Hi @sebastienhannay. can you provide your 60 ChartDataEntry values? so I get more information about the crash. |
Make sure you use x values are index. You can later change X values with value formatter. Example: |
We are building a timeline so x values are a function on Here are my 60 values that cause the crash :
|
okay values seems to be fine. Do you have any X offset or Y offset assigned to your chart view ? |
if you have any offset values try this fileprivate init(min: Int, max: Int) { 50 - is your range given in |
I have offset on X and also custom min and max values on both X and Y (add some padding to the charts so it matches our requirements). I can scroll in the chart horizontally but cannot zoom in or zoom out. I just noticed that the crash happens when the scroll reach the very last point of the dataset (didn't notice earlier as I was automatically scrolling to the end on display) so maybe it is related to the dataset or custom viewing window. Tried your solution, it prevent the crash but as soon as the last point is displayed, the line disappear but i still have the datapoints |
I can scroll in the chart horizontally but cannot zoom in or zoom out -> for this issue check if the scaleY is enabled and pinchZoom enabled Can you share all of your offset codes along with the offset values |
About the offset, I tried to isolate the issue as much as possible and it looks like setting any For the data that I shared, I set |
setting xAxis.axisMaximum will force the chart to stop at that particular value.Check if you have same functionality without setting axisMaximum. |
Yes it works correctly when I don't set axisMaximum so it can be a quick fix but it will have some differences in the display. |
Seems like the issue is when you try to find the closest point to the max. The comparison seems to be : |
Yeah I think you are using x values in Data Entry as timestamps instead you can try to use the index of the loop in which you append the values as x values. then use value formatter to IndexAxisFormatter and give your timestamps And then you can set Axis Maximum. Lets say I have total of 60 values my Axis Maximum would be 70 and I should manually add the timestamps for the 10 extra points that's needed to be shown in the graph(I'm not sure about this part) In case if you are not using timestamps as x values |
They are not directly timestamps but derive of timestamps. The problem is that I don't have values for every day and can't add extra points to my chart without losing its accuracy. I need a scale that represent a real time scale and all points that are on my chart should be associated with a value added by the user. So your solution doesn't seems to fit my needs... Correct me if I'm wrong but if I use xOffset instead of xAxis.axisMaximum I will get the same padding at the beginning and end of the chart which, again, doesn't really fit my needs. |
Yes you will get at both ends but you can move your chart view to last xValue with moveViewToX which displays your chart view's last x point with padding on right side alone , unless user decides to scroll to very first value. |
I see, could also be a quick fix but it's it would be better if could work the same way as in v3.6. Looks like this version bring more limitations than the previous one... I saw a branch that restore the old way of calculating xbounds (https://github.com/danielgindi/Charts/tree/bugfix/xbounds-iterator) that may fix my issue but I don't know if it limits some newer features. Would be awesome if I could have the same display as before without adding some tricks in the code to compensate what seems to be a regression. |
The version of Charts you linked is of Version 4.0.0 I think you won't lose much on new features probably 4.0.2 have some bug fixes. |
I mean as it roll back the new calculation of xbounds introduce in 4.0.0 to the one in 3.6. |
I am also seeing this in version 4.0.2. When I set a maximum value on the x axis, I get a sporadic crash, and the line disappears when I zoom out all the way. |
Did you set visibleXRange ? |
No, will that help? It seems to automatically limit the zoom so I can't zoom out past the extent of the data. (Just to clarify my last post, the line disappears when I zoom out so all the data points are visible; I don't need to zoom out a crazy amount.) |
In case if you don't want to scale a crazy amount you can set maximum scale limit with
Change 1.3 to match whatever zoom level you wanted to limit it. |
I'm also seeing this issue. I'm using time interval since 1970 as x values and drawing a |
@PWrzesinski Yes charts will not function properly when time stamps are used. You can make use of indexes instead of timestamps and change the x axis values later with Axis Formatter Class. Like this #4798 (comment) |
Thanks @k1ran-ak, I've reduced the numbers so instead of starting 1.01.1970 they will start with the lowest date from all values, so if my earliest data point is 1.01.2021 that will be value 0. This fixed the crash for me. Still I must say, Charts is pretty close to working with dates since 1970, apart from this crash I've only encountered the issue with candlesticks being very thin which feels like it should be fixable. There is also one unrelated issue, but otherwise I'm super happy with the framework! |
@PWrzesinski If you are using timestamps as X-axis values, you will be getting a thin candle stick chart as the difference between two consequetive timestamps is large. Thats why I earlier mentioned to use indices of the timestamps array ie. 0,1,2 .... and later change the x axis labels with Axis formatter class. If you want me to explain in detail I can do it so let me know if there is anything I could do to help you. |
Thank you, I appreciate the help! There are a few reasons I'd like to avoid using the index approach you're suggesting, but your comment clarified for me why the candlesticks are so thin. In the end I simply divided the timestamps by 10 after offsetting them to the start date and now they look good. Thanks! 😅 |
@PWrzesinski Glad I could be of any help 😊. |
This does appear to be a bug. It's happening to me on a LineChartView with the following data points: It only happens if I set the xMin and xMax values of the x axis (I'm setting them to -4 and 7). Some of the points are not rendered, and then if I zoom in a little and pan to the left, I hit this crash. I'm not too familiar with the code, but it looks like the problem is in BarLineScatterCandleBubbleRenderer.XBounds.set(). I think it's trying to figure out the range of indices of points to render, but if you've set the xMin and xMax to be even a little larger than the full range of the data (which seems to a reasonable thing to do) then the range is not calculated correctly. (looking back in this thread, this is the same place in the code that @sebastienhannay identified also.) Would love to get this resolved; I'm currently stuck on version 3.6 due to this bug! 😀 |
Also experiencing this bug - seems like #4839 is the cure 😄 |
Can someone try with the fix from #4829? (it is already in master) |
@FelixHerrmann I verified that the latest build from the master branch does fix the problem! |
Awesome, thanks for checking!! If @sebastienhannay can confirm too, this issue can be closed I would say... |
Sorry for the late answer, the latest version seems to work well on my side too. |
What did you do?
Upgrade from 3.6.0 to 4.0.2
What happened ?
Most drawing of charts leads to a crash when building iterator in
extension BarLineScatterCandleBubbleRenderer.XBounds: Sequence
because Range requires lowerBound <= upperBound
let entryTo = dataSet.entryForXValue(high, closestToY: .nan, rounding: .up)
is nil. It looks like the closest found is < endIndex in the dataset.I use custom minimum and maximum axis values and visible range.
The same code was working perfectly in v3.6.
I also tried to rollback to 3.6 as a temporary workaround but the project doesn't compile anymore with XCode 13.3.
Charts Environment
Charts version/Branch/Commit Number: 4.0.2
Xcode version: 13.3 (13E113)
Swift version: 5
Platform(s) running Charts: iOS
macOS version running Xcode: 12.0.1 (21A559)
The text was updated successfully, but these errors were encountered: