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

Empty Line Chart, setVisibleXRangeMaximum causing Fatal error: Double cannot be converted to Int #4109

Closed
1 task done
Nuthen opened this issue Aug 15, 2019 · 1 comment
Closed
1 task done

Comments

@Nuthen
Copy link

Nuthen commented Aug 15, 2019

What did you do?

On a Line Chart with zero entries, I called setVisibleXRangeMaximum(10)

What did you expect to happen?

I expect it to display an empty chart.

What happened instead?

The next time the line chart is drawn, it crashes with this message:

Fatal error: Double value cannot be converted to Int because it is either infinite or NaN.

At AxisRendererBase::computeAxisValues - line 120.

Charts Environment

Charts version/Branch/Commit Number: 3.3.0
Xcode version: 10.3
Swift version: 5
Platform(s) running Charts: iPhone
macOS version running Xcode: 10.14.5

Demo Project

Initialize a chart like normal but don't add any entries to it.
Call setVisibleXRangeMaximum(10) - number doesn't matter.
Next time it draws the graph, the crash occurs.

As mentioned among some other issues, it's a bad idea to create a chart with empty data.
In my app, I'm slowly adding data to the chart over time, so it's only natural for it to start out empty.

This crash can also occur if you remove entries from a line chart to make it have zero entries.

I'm not sure if the same crash happens on other types of charts.

In my project, I'll make sure that this function doesn't get called before any data is added.
I wanted to add this issue for visibility in case someone else runs into this issue, and if I have time I'll create a PR to stop the crash from occurring or to provide a better explanation when the crash happens.

Related: #2888 #1945 #3352 #2845 #1491

https://stackoverflow.com/questions/45496912/how-to-clear-a-chart-and-then-add-data-to-it-in-swift-3-using-chartview-clear

@liuxuan30
Copy link
Member

I have to hold this as, when you know it's empty, you shouldn't call set visible range.
There has been arguing that who should take care of these exceptions, and currently I think the user of this library should take actions before us.

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