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

Array index out of range when removing entries from DataSet #203

Closed
BrandonShega opened this issue Jul 10, 2015 · 4 comments
Closed

Array index out of range when removing entries from DataSet #203

BrandonShega opened this issue Jul 10, 2015 · 4 comments

Comments

@BrandonShega
Copy link

Is there a specific reason why I am getting fatal error: Array index out of range: with this code?

for (int i = 0; i < [self.currentBarChartDataSet entryCount]; i++) {

        [self.currentBarChartDataSet removeEntryWithXIndex:i];
//        [self.pastBarChartDataSet removeEntryWithXIndex:i];

}

I'm basically trying to remove all data from the bar chart in prepareForReuse in a UICollectionViewCell so that the chart isn't visible when the collection view is reloaded.

If I log the count, it is 7 and the loop is running 7 times.

@BrandonShega
Copy link
Author

Ok I changed my code to this because I realized what I was doing wrong before, but it's still crashing with the same error

    NSInteger count = [self.currentBarChartDataSet entryCount];

    for (int i = 0; i < count; i++) {

        [self.currentBarChartDataSet removeEntryWithXIndex:0];
//        [self.pastBarChartDataSet removeEntryWithXIndex:i];

    }

@BrandonShega
Copy link
Author

It's crashing on this line #395 in ChartDataSet.swift
calcMinMax(start: _lastStart, end: _lastEnd)

@danielgindi
Copy link
Collaborator

Call notifyDataSetChanged() after done changing the data

On Fri, Jul 10, 2015 at 6:50 PM, Brandon Shega notifications@github.com
wrote:

It's crashing on this line #395 in ChartDataSet.swift
calcMinMax(start: _lastStart, end: _lastEnd)


Reply to this email directly or view it on GitHub
#203 (comment)
.

@BrandonShega
Copy link
Author

It doesn't even let me get that far, it's crashing before it even moves over the line where the entry is removed.

liuxuan30 added a commit to liuxuan30/Charts that referenced this issue Jul 28, 2015
try to fix wrong position bug. use entry.xIndex instead of j of dataSet.entryCount to calculate the offset and position

apply the same logic for getMarkerPosition

add fix for horizontal bar chart

merge from upstream master

Wrong demo navigation title

Maximum negative value was confused...

Removed unused code

startAtZeroEnabled killed that range when all values are negative

Bound check for horizontal bars was wrong (Fixed issue ChartsOrg#211)

Fixed a crash when removing an entry (Fixed issue ChartsOrg#203)

Removed redundant calls

Inverted axis mode taken care of in stacked bars

Added back the 3rd dataset in demo project

Bumped to 2.1.1

Improvements to stacked bars

Major improvements to Highlights

Improvements concerning value-drawing in barcharts.

Improvements and bugfixes concerning highlighting.

Fix ChartMarker position for stacked-bars

Removed redundant function

Feature to allow forcing YAxis label-count

Bumped to 2.1.2

CONTRIBUTING.md

You will now see this when creating new issues. Ha ha!
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