Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JacobWrenn opened this issue Aug 8, 2020 · 16 comments
Open

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

JacobWrenn opened this issue Aug 8, 2020 · 16 comments
Labels
enhancement New feature or request Fundamental

Comments

@JacobWrenn
Copy link

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

@imaNNeo imaNNeo added enhancement New feature or request Fundamental labels Aug 10, 2020
@imaNNeo
Copy link
Owner

imaNNeo commented Aug 10, 2020

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!

@JacobWrenn
Copy link
Author

Thanks!

@JagandeepBrar
Copy link

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

@akshaybhange
Copy link

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

@jamesnicholls04
Copy link

jamesnicholls04 commented Sep 25, 2020

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 👍

@MitchSRobinson
Copy link

Yep, jumping on the bandwagon! This would be awesome

@con-cis
Copy link

con-cis commented Feb 1, 2021

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

@rashidkhaleefa
Copy link

Any update regarding this feature?

@maxpelna
Copy link

maxpelna commented Jul 8, 2021

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

Thank you!

@hpiu
Copy link

hpiu commented Apr 6, 2022

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

@jay11125
Copy link

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.

@millie-molly
Copy link

any updates?

@kyeshmz
Copy link

kyeshmz commented Jul 27, 2023

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;
      },
      [],
    );
    ```

@Dartek12
Copy link
Contributor

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.
#1445

@jebstern
Copy link

Any progress on this? There's an open PR

@sobriver
Copy link

sobriver commented Dec 9, 2023

mark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Fundamental
Projects
None yet
Development

No branches or pull requests