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

when BarChartView has no chart data availble, drag will lead crash. #607

Closed
liuhuan1991 opened this issue Dec 13, 2015 · 3 comments
Closed

Comments

@liuhuan1991
Copy link

the crash is at ChartHighlighter.swift file, crash message is "EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0)" .
and the crash breakpoint at the method:

internal func getXIndex(x: Double) -> Int
    {
        // create an array of the touch-point
        var pt = CGPoint(x: x, y: 0.0)

        // take any transformer to determine the x-axis value
        _chart?.getTransformer(ChartYAxis.AxisDependency.Left).pixelToValue(&pt)

        return Int(round(pt.x))
    }

And I set _chartView.highlightPerTapEnabled = NO; _chartView.highlightPerDragEnabled = NO;, the bug will fixed.

@liuxuan30
Copy link
Member

If your bar chart has no data, it should display 'No chart data available. You need to provide data for the chart'. And it won't zoom or scroll, as exptected.

what's your data looks like? I tried with ChatsDemo, not setting chart.data by commenting out chartView.data = data
it will not crash. Could you provide a data code snippet with ChartsDemo so we can reproduce it?

If your data is empty, but it actually did trigger getXIndex(), and the matrix will be a mess, so pixelToValue will calculates NaN and leads to crash. By default, it will check data and will not goes to getXIndex() or drawRect if no data available. Have you modified the code?

@liuhuan1991
Copy link
Author

Modify and replace the method of BarChartViewController.m:

- (void)setDataCount:(int)count range:(double)range
{
    BarChartData *charData = [[BarChartData alloc] initWithXVals:@[] dataSets:@[]];
    _chartView.data = charData;
}

then, drag with BarChartView, it will be crash.

And if we set the highlightPerTapEnabled and highlightPerDragEnabled of chartView as NO, the bug will fixed.

@liuxuan30
Copy link
Member

Ah I see. Seems duplicated to #577
There is a PR #582 pending. You can use the code there to prevent the crash.

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

No branches or pull requests

2 participants