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

HorizontalBarChartView with multiple data set crashes on tap #1339

Closed
cuddle-sujeet opened this issue Aug 19, 2016 · 4 comments
Closed

HorizontalBarChartView with multiple data set crashes on tap #1339

cuddle-sujeet opened this issue Aug 19, 2016 · 4 comments
Labels

Comments

@cuddle-sujeet
Copy link

cuddle-sujeet commented Aug 19, 2016

HorizontalBarViewIssue.zip

I am using a HorizontalBarChartView to display a multiple dataset. But the app crashes on tap.

@liuxuan30 liuxuan30 added the bug label Aug 22, 2016
@chuynadamas
Copy link
Contributor

@liuxuan30 I saw the problem: Over the HorizontalBarChartHighlighter class you have this method

    public override func getXIndex(x: CGFloat) -> Int
    {
        if let barData = self.chart?.data as? BarChartData
            where !barData.isGrouped
        {
            // create an array of the touch-point
            var pt = CGPoint(x: 0.0, y: x)

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

            return Int(round(pt.y))
        }
        else
        {
             return getXIndex(x)
        }
    }

The multiple dataSets charts has the property isGrouped enabled, so this function will be called forever, and this crash the app. I have the same problem and I'd like to ask which is the correct function that we need to call if we have a isGrouped chart to get the xIndex 🙃

Thanks in advance 👾

@chuynadamas
Copy link
Contributor

chuynadamas commented Aug 22, 2016

@liuxuan30 @cuddle-sujeet I guess that i figure out what was the problem, I guess that you wanted to call the super getXIndex method when the condition fail. Just like that:

    public override func getXIndex(x: CGFloat) -> Int
    {
        if let barData = self.chart?.data as? BarChartData
            where !barData.isGrouped
        {
            // create an array of the touch-point
            var pt = CGPoint(x: 0.0, y: x)

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

            return Int(round(pt.y))
        }
        else
        {
            return super.getXIndex(x)
        }
    }

The parent method has the correct code to handle the grouped charts, So this solve the problem, I don't think that this needs a PR, but I guess you need to include for all the people who is working with the version 2.2.5, Idk if the 3.0 version has the same problem.

Thanks in advance 👾🙃 i'd like to be a contributor of this great repo! :)

@danielgindi
Copy link
Collaborator

This does not happen on Charts 3.0, there are no more x-indexes, and the highlighters have been competely re-written

@cuddle-sujeet
Copy link
Author

Sorry for late reply.
Thanks @chuynadamas your solution does work for me.
hopefully this will be updated in future version.

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

No branches or pull requests

4 participants