Blogs

The Progress Bar - DevExpress XPF Blog

How to animate series with WPF Charts

     

In a previous post, I talked about an example where the chart control’s BoundDataChanged event handler was used to calculate a series summary and display that as a custom field within the chart’s legend box.

The BoundDataChanged event is triggered every time the chart control generates series points based on a data source. While this may not sound very exciting at first, it’s value increases when you consider all the possibilities of being able to perform certain routines before the series are drawn. From being able to retrieve live series data for display elsewhere in your UI, to animating the series as they are being drawn, the possibilities are endless.

So here’s an example… animating the series using series templates. We want the final product to draw the series as it is populating it with points:

WPF_Charts_Animate_Series 

The following code is used within the BoundDataChanged event handlerto create the animation for the series template.

   1: private void chartControl1_BoundDataChanged(object sender, RoutedEventArgs e) {
   2:     seriesAnimation.Animations.Clear();
   3:     foreach (Series series in chartControl1.Diagram.Series) {
   4:         SeriesAnimation tmpSeriesAnim = new SeriesAnimation();
   5:         SeriesAnimationAction seriesAction = new SeriesUnwindingAction();
   6:         tmpSeriesAnim.Actions.Add(seriesAction);
   7:         seriesAnimation.Animations.Add(tmpSeriesAnim);
   8:         tmpSeriesAnim.TargetSeries = series;
   9:     }
  10:     DoubleAnimation animation = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(5)));
  11:     seriesAnimation.BeginAnimation(ChartAnimationRecord.ProgressProperty, animation, HandoffBehavior.SnapshotAndReplace);
  12: }

Give it a try…

Download the source code for this example from CodeCentral: http://www.devexpress.com/Support/Center/e/E2412.aspx

Also, keep an eye out on the DevExpress Channel and this blog for an upcoming video that demonstrates this feature in action.

Published Aug 23 2010, 05:00 PM by Emil Mesropian (DevExpress)
Filed under: , ,
Technorati tags: Charts, DXCharts, WPF
Bookmark and Share

Comments

No Comments
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.