1

I'm using the Swift version of the 'Charts' framework in iOS ( https://github.com/danielgindi/Charts ) to chart a series of lines. If I chart any one of the lines, it works fine.

But if I attempt to chart all of the lines, only the last line appears on the chart correctly, and the other lines display only their first chart point each. (See image below.)

Here's my code:

    func refreshChart() {
        var chartDataSets: [LineChartDataSet] = []
        var xDistance = 0.0
        for lineIndex in 0..<4 {
            var chartEntries: [ChartDataEntry] = []  //  New set of chart entries for each line
            var yElevation = Double(lineIndex)
            for _ in 0..<10 {
                xDistance += 1.0
                yElevation += 1.0
                logger.log("\(lineIndex):  \(xDistance), \(yElevation)")
                chartEntries.append(ChartDataEntry(x: xDistance, y: yElevation))
            }
            chartDataSets.append(LineChartDataSet(entries: chartEntries, label: "Elevation"))
        }
        let chartData = LineChartData(dataSets: chartDataSets)
        lineChartView.data = chartData
        
        for dataSet in chartData {
            for i in 0..<dataSet.entryCount {
                if let entry = dataSet.entryForIndex(i) {
                    print("\(i):  \(entry.x), \(entry.y)")
                }
            }
        }
    }

The diagnostic output at the end displays all the X, Y values that I would expect for each of the 4 lines. They just don't appear on the chart!

What am I doing wrong here?

enter image description here

Son of a Beach
  • 1,733
  • 1
  • 11
  • 29
  • I have found that this appears to be a bug (or feature?) of the iOS Charts library, and there is a work-around documented at https://stackoverflow.com/questions/66562983/ios-charts-will-not-draw-multiple-datasets-when-the-sets-use-different-ranges-of and at https://github.com/danielgindi/Charts/issues/4597. So I'm voting to close my own question. – Son of a Beach Apr 10 '22 at 04:21

0 Answers0