imaNNeo / fl_chart

FL Chart is a highly customizable Flutter chart library that supports Line Chart, Bar Chart, Pie Chart, Scatter Chart, and Radar Chart.
https://flchart.dev
MIT License
6.85k stars 1.77k forks source link

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

Open JacobWrenn opened 4 years ago

JacobWrenn commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Thanks!

JagandeepBrar commented 4 years ago

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 commented 4 years ago

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

jamesnicholls04 commented 4 years ago

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 commented 4 years ago

Yep, jumping on the bandwagon! This would be awesome

con-cis commented 3 years ago

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

rashidkhaleefa commented 3 years ago

Any update regarding this feature?

maxpelna commented 3 years ago

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

Thank you!

hpiu commented 2 years ago

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

jay11125 commented 1 year ago

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 commented 1 year ago

any updates?

kyeshmz commented 1 year ago

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 commented 1 year ago

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

jebstern commented 1 year ago

Any progress on this? There's an open PR

sobriver commented 11 months ago

mark