Skip to main content

How to: Implement a Custom Series Animation

  • 2 minutes to read

To implement a custom series animation for series views supported by the Cartesian (XY) diagram, design a class derived from the XYSeriesAnimationBase class and override the base class SeriesAnimationBase.ApplyState method. The following objects are passed to this method as parameters.

  • SceneModifier sceneModifier - this object allows you to apply the required transformations to your series.
  • Rectangle diagramBounds - this object specifies bounds of the diagram on which an animated series is drawn.
  • float progress - this value specifies the current progress of the animation.
using DevExpress.XtraCharts;
using System.Drawing;

namespace XYSeriesCustomAnimationSample {
    class XYSeriesRotateAndZoomAnimation : XYSeriesAnimationBase {
        const int defaultRotationCount = 1;

        int rotationCount = defaultRotationCount;
        public int RotationCount {
            get { return rotationCount; }
            set { rotationCount = value; }
        }

        public override void ApplyState(SceneModifier modifier, Rectangle diagramBounds, float progress) {
            float currentWidth = diagramBounds.Width * progress;
            float currentHeight = diagramBounds.Height * progress;

            float diagramCenterX = diagramBounds.X + diagramBounds.Width / 2.0f;
            float diagramCenterY = diagramBounds.Y + diagramBounds.Height / 2.0f;

            float dx = (currentWidth - diagramBounds.Width) / 2;
            float dy = (currentHeight - diagramBounds.Height) / 2;

            modifier.Translate(-dx, -dy);
            modifier.Scale(progress, progress);

            modifier.Translate(diagramCenterX, diagramCenterY);
            modifier.Rotate(progress * 360 * RotationCount);
            modifier.Translate(-diagramCenterX, -diagramCenterY);
        }

        protected override ChartElement CreateObjectForClone() {
            return new XYSeriesRotateAndZoomAnimation();
        }
    }
}