diff --git a/Source/Charts/Data/Implementations/Standard/ChartData.swift b/Source/Charts/Data/Implementations/Standard/ChartData.swift index e5e22d0ac2..81fc37b3a8 100644 --- a/Source/Charts/Data/Implementations/Standard/ChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/ChartData.swift @@ -422,7 +422,7 @@ open class ChartData: NSObject, ExpressibleByArrayLiteral /// 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 } + return self.max { $0.entryCount < $1.entryCount } } } diff --git a/Tests/ChartsTests/ChartDataTests.swift b/Tests/ChartsTests/ChartDataTests.swift index 5b697f710b..0520aba227 100644 --- a/Tests/ChartsTests/ChartDataTests.swift +++ b/Tests/ChartsTests/ChartDataTests.swift @@ -64,4 +64,18 @@ class ChartDataTests: XCTestCase { XCTAssertTrue(data.dataSet(forLabel: SetLabels.badLabel, ignorecase: true) == nil) XCTAssertTrue(data.dataSet(forLabel: SetLabels.badLabel, ignorecase: false) == nil) } + + func testMaxEntryCountSet() throws { + let dataSet1 = BarChartDataSet(entries: (0 ..< 4).map { BarChartDataEntry(x: Double($0), y: Double($0)) }, + label: "data-set-1") + let dataSet2 = BarChartDataSet(entries: (0 ..< 3).map { BarChartDataEntry(x: Double($0), y: Double($0)) }, + label: "data-set-2") + let dataSet3 = BarChartDataSet(entries: [BarChartDataEntry(x: 0, y: 0)], + label: "data-set-3") + let data = BarChartData(dataSets: [dataSet1, dataSet2, dataSet3]) + + let maxEntryCountSet = try XCTUnwrap(data.maxEntryCountSet as? BarChartDataSet) + + XCTAssertEqual(maxEntryCountSet, dataSet1) + } }