ChartsOrg / ChartsOrg/Charts

Crash at BarChartRenderer when render bat with multiple data sets

Open
#4,821 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

* [x] I've read, understood, and done my best to follow the [*CONTRIBUTING guidelines](https://github.com/jjatie/Charts/blob/master/CONTRIBUTING.md).

## What did you do?

Given that I have an array of `BarChartDataSet` which is `let dataSets [4 entries, 3 entries, 1 entry]`.
Then I make a `BarChartData(dataSets: dataSets)` with that set.
When I render the bar chart with that data set it will crash at `BarChartRenderer`.
```
accessibilityOrderedElements[j/stackSize].append(element)
```

with an out of exception of index out of range.

## What did you expect to happen?

It should not crash.

## What happened instead?

I found out that the ChartData > maxEntryCountSet implementation is wrong.
It returns 1 in my example in stead of 4.
I think the fixing should be
```
/// The DataSet object with the maximum number of entries or null if there are no DataSets.
@objc open var maxEntryCountSet: Element?
{
return self.max { $0.entryCount < $1.entryCount }
}
```

## Charts Environment

**Charts version/Branch/Commit Number: 4.0.2**
**Xcode version: 13.2.1**
**Swift version: 5.2.4**
**Platform(s) running Charts: iOS**
**macOS version running Xcode: 12.3**

Contributor guide

Open the contributing guide

Research direction

Start at ChartData.maxEntryCountSet and the BarChartRenderer access to accessibilityOrderedElements[j/stackSize]. Reproduce the crash with BarChartData containing datasets of 4, 3, and 1 entries, then verify that the maximum entry count is selected correctly and the chart no longer raises an index-out-of-range exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
data-visualization, mobile
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.