fl_chart icon indicating copy to clipboard operation
fl_chart copied to clipboard

How to animate in the bars when the chart is first shown?

Open JacobWrenn opened this issue 4 years ago • 16 comments

I would like the bars to start at zero and then animate into their actual positions for the initial set of data.

Please see this example of what I would like to achieve: ezgif com-video-to-gif

JacobWrenn avatar Aug 08 '20 17:08 JacobWrenn

Hi there, I like this feature, and we will implement an initial animation for all of the charts ASAP. Thanks for reporting, and stay tuned!

imaNNeo avatar Aug 10 '20 18:08 imaNNeo

Thanks!

JacobWrenn avatar Aug 11 '20 07:08 JacobWrenn

Would love this feature myself as well! For React web applications I used Recharts, which have some really nice intro animations: http://recharts.org/en-US/api

JagandeepBrar avatar Sep 09 '20 02:09 JagandeepBrar

Hi Team, any date decided for adding this to library ?

akshaybhange avatar Sep 23 '20 18:09 akshaybhange

I second/third/fourth this!

Inspiration: https://dribbble.com/shots/1873362-Squadlance-Concept/attachments/328342

That the actual value animates with the line graph is really cool - I wonder whether this could be part of the solution?

Incredible work! Love this library 👍

jamesnicholls04 avatar Sep 25 '20 16:09 jamesnicholls04

Yep, jumping on the bandwagon! This would be awesome

MitchSRobinson avatar Oct 05 '20 21:10 MitchSRobinson

You can do this with Staggered Animations: https://flutter.dev/docs/development/ui/animations/staggered-animations

con-cis avatar Feb 01 '21 17:02 con-cis

Any update regarding this feature?

rashidkhaleefa avatar Feb 28 '21 20:02 rashidkhaleefa

You can do this with Staggered Animations: https://flutter.dev/docs/development/ui/animations/staggered-animations

Thank you!

maxpelna avatar Jul 08 '21 08:07 maxpelna

is there any update regarding this? or is it still Staggered animation that is the way to go? thx for good library btw :)

hpiu avatar Apr 06 '22 16:04 hpiu

You can do this with Staggered Animations: https://flutter.dev/docs/development/ui/animations/staggered-animations

Can you please share your code? I am new to flutter animations and unable to figure how to use staggered animations to achieve this.

jay11125 avatar Mar 19 '23 19:03 jay11125

any updates?

millie-molly avatar Jun 12 '23 07:06 millie-molly

To my understanding, you would have to tween to each coordinate and update each frame, highly opinionated with riverpod and flutter hooks, but this is the code.

  final animationController = useAnimationController(
      duration: const Duration(milliseconds: 400),
    );
    useAnimation(animationController);

    List<ItemGraphModel> initialAnimation(List<ItemGraphModel> data) {
      final animatedData = <ItemGraphModel>[];
      for (var i = 0; i < data.length; i++) {
        final tween = Tween<double>(
          begin: 0,
          end: data[i].num.toDouble(),
        )
            .chain(
              CurveTween(
                curve: Curves.easeOutCubic,
              ),
            )
            .animate(animationController);
        animatedData.add(data[i].copyWith(num: tween.value.toInt()));
      }
      return animatedData;
    }

    useAsyncEffect(
      () async {
        await Future.delayed(const Duration(milliseconds: 200), () {
          ref.read(itemGraphStateProvider.notifier).setType(ItemGraphType.ONE_WEEK);

          final data = [
            ItemGraphModel(num: 108, date: DateTime(2023, 7, 24, 1, 1, 1)),
            ItemGraphModel(num: 153, date: DateTime(2023, 7, 25, 1, 1, 1)),
            ItemGraphModel(num: 120, date: DateTime(2023, 7, 26, 1, 1, 1)),
            ItemGraphModel(num: 104, date: DateTime(2023, 7, 27, 1, 1, 1)),
            ItemGraphModel(num: 155, date: DateTime(2023, 7, 28, 1, 1, 1)),
            ItemGraphModel(num: 173, date: DateTime(2023, 7, 29, 1, 1, 1)),
            ItemGraphModel(num: 186, date: DateTime(2023, 7, 30, 1, 1, 1))
          ];
          final animatedData = initialAnimation(data);
          ref.read(itemGraphStateProvider.notifier).setData(animatedData);

          animationController
            ..forward(from: 0)
            ..addListener(() {
              final animatedData = initialAnimation(data);

              ref.read(itemGraphStateProvider.notifier).setData(animatedData);
            });
        });
        return null;
      },
      [],
    );
    ```

kyeshmz avatar Jul 27 '23 00:07 kyeshmz

Hello folks, I gave it a go in this PR (implemented starting animation for line/bar/radar chart). I have included a gif animation for the bar chart to show how it animates from zeroed values to the initially provided ones. https://github.com/imaNNeo/fl_chart/pull/1445

Dartek12 avatar Sep 22 '23 22:09 Dartek12

Any progress on this? There's an open PR

jebstern avatar Oct 16 '23 08:10 jebstern

mark

sobriver avatar Dec 09 '23 07:12 sobriver