Charts icon indicating copy to clipboard operation
Charts copied to clipboard

Bar Chart: Adjust visible Y range according to currently visible maximum value

Open frogg opened this issue 4 years ago • 2 comments

Thanks a lot for your lovely Charts package! I am currently using it to develop a visualization component for one of my apps.

The remaining thing I am struggling with is changing the visible vertical Y range depending on the currently visible maximum value.

Here‘s an example to make things clear: Most values are around ±20, but there's one outlier with a value of 100:

Screen Recording 2021-11-25 at 22 54 46

I want to adjust the Y range while this one outlier is not visible.

Right now I am using the chartViewDidEndPanning method to get the currently visible X range using self.lowestVisibleX and self.highestVisibleX. Using this information I can check in my data set what the current maximum Y value is. Using this value, I try to adjust the visibleYRange:

self.chartView.setVisibleYRangeMaximum(maximum, axis: .right)
self.chartView.setVisibleYRangeMinimum(maximum, axis: .right)

And, because I want the Y axis to always start at 0, I am also calling this method:

self.chartView.moveViewTo(xValue: self.chartView.lowestVisibleX, yValue: maximum / 2, axis: .right)

This solution kinda works, but it is also kinda chunky:

Screen Recording 2021-11-25 at 23 04 10

I am wondering if there‘s a more elegant (built-in?) way, maybe even animated just like Apple is doing it in the Health app: RPReplay_Final1637877946

Happy to hear any feedback, or reports of people who have been working towards similar goals 🙏

frogg avatar Nov 25 '21 22:11 frogg

Hey mate, I know it's been almost 3 years but have you found a solution after all? Struggling with a similar thing currently.

ruslanosaur avatar Sep 04 '24 20:09 ruslanosaur

@ruslanosaur I dont think this package is maintained anymore, I have switched to Apple’s SwiftUI Charts which is super cool: https://developer.apple.com/documentation/charts

frogg avatar Sep 04 '24 20:09 frogg