ChartsOrg / Charts

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Apache License 2.0
27.48k stars 5.98k forks source link

If the values are close, the chart won't animate #3365

Open rptoma opened 6 years ago

rptoma commented 6 years ago

What did you do?

I have a BarChartView with two data entries with the values (1, 1000000) and (2, 1000100). I try to animated the chart.

What did you expect to happen?

The chart doesn't get animated.

What happened instead?

If the command is like barChartView.animate(xAxisDuration: 2, yAxisDuration: 2), there will be an empty chart for 2 seconds, that suddenly appears with no animations. If the values were more far apart (for example, 1000000 and 10), the animation would've worked.

Charts Environment

Charts version/Branch/Commit Number: Xcode version: 9 Swift version: 4 Platform(s) running Charts: iOS macOS version running Xcode: High Sierra

Demo Project

https://gist.github.com/rptoma/37cef9c394161dcd074e59a678a0e79c

thierryH91200 commented 6 years ago

replace barChartView.animate(xAxisDuration: 2, yAxisDuration: 2) by DispatchQueue.main.async(execute: {() -> Void in barChartView.animate((xAxisDuration: 2.0, yAxisDuration: 2.0) })

rptoma commented 6 years ago

I did it and the result is the same.

thierryH91200 commented 6 years ago

the only solution I found

    let leftAxis                  = barChartView.leftAxis
    leftAxis.axisMinimum = 100000 or less
rptoma commented 6 years ago

This is how my code looks now:

barChartView.leftAxis.axisMinimum = 100000

DispatchQueue.main.async {
   barChartView.animate(xAxisDuration: 1.5, yAxisDuration: 1.5)
}

and still doesn't work. Did you do anything else, in addition?

thierryH91200 commented 6 years ago

the problem is the same with

 let yVals = [BarChartDataEntry(x: 1, y: 1000 ), BarChartDataEntry(x: 2, y: 1010 )]
        barChartView.leftAxis.axisMinimum = 1000

but not with

 barChartView.leftAxis.axisMinimum = 0
andepopande commented 4 years ago

I noticed the same. I think the animation assumes that it should start from axisMinimum = 0, regardless what you set as axisMinimum, so it will take a few seconds to animate from y=0 to y=1000 -> you notice no animation at all for a few seconds and suddenly it appears

kallik commented 3 years ago

Anyone found a way for animations to work for y>0, I'm working with yaxis range of 123.34 -> 125.34 and when animating y axis the animator starts at zero (my chart starts at 123ish).