Charts icon indicating copy to clipboard operation
Charts copied to clipboard

LineChart disappears when zoom on X axe

Open francescofnt opened this issue 3 years ago • 3 comments

What did you do?

I have a LineChartView to display temperatures over a day.

        self.lineChartView.gridBackgroundColor = .white
        self.lineChartView.borderLineWidth = 2
        self.lineChartView.borderColor = .systemGray
        self.lineChartView.chartDescription.text = ""
        self.lineChartView.gridBackgroundColor = .clear
        self.lineChartView.backgroundColor = .clear
        self.lineChartView.pinchZoomEnabled = false
        self.lineChartView.doubleTapToZoomEnabled = false
        self.lineChartView.delegate = self
        self.lineChartView.scaleYEnabled = false
        self.lineChartView.scaleXEnabled = true
        self.lineChartView.extraBottomOffset = 10
image

What did you expect to happen?

Since I have a lot of values for a single day, and all single value is really important, I need to zoom over the X axe disabling zoom on Y axe.

What happened instead?

The problem is that the line disappears when I zoom-in. If I set y-zoom to true the line remains on screen, but If I set it to false, when zooming it disappears.

image

zooming

Charts Environment

Charts version: 4.1.0 Xcode version: 14.2 Swift version: 5 Platform(s) running Charts: macOS macOS version running Xcode: Ventura 13.0

francescofnt avatar Apr 10 '23 09:04 francescofnt

Update to v5.0.0 and the problem still present. I have no idea how to resolve.

francescofnt avatar Jun 10 '23 21:06 francescofnt

We had a similar issue, finally found the solution.

Issue was that when giving value to graph it was generating array of data in descending order.

Screenshot 2024-06-26 at 11 52 42 AM

so we've added logic revere value if it's in descending order

Screenshot 2024-06-26 at 11 52 13 AM

and assigning data after doing this,

// values.reverse() if needed
let set1 = LineChartDataSet(entries: values, label: "")
let data = LineChartData(dataSets: [set1])
self.lineChartView?.data = data

after doing this, graph was able to scroll and zoom properly without disappearing or glitching.

DEEPmagicman avatar Jun 26 '24 06:06 DEEPmagicman