代码之家  ›  专栏  ›  技术社区  ›  Pharabus

BounceEase和Silverlight 4 BarSeries

  •  1
  • Pharabus  · 技术社区  · 15 年前

    我试图让一个条形图系列在绘图时“反弹”,我假设反弹过渡函数可以做到这一点,但线条只是淡入淡出,我已经发布了下面的XAML和代码,有人知道我哪里出错了,或者它比我更复杂,我对Silverlight还比较陌生。

    XAML

    <Grid x:Name="LayoutRoot" Background="White">
        <chartingToolkit:Chart x:Name="MyChart">
            <chartingToolkit:BarSeries Title="Sales" ItemsSource="{Binding}" IndependentValuePath="Name" DependentValuePath="Value" AnimationSequence="FirstToLast" TransitionDuration="00:00:3">
                <chartingToolkit:BarSeries.TransitionEasingFunction>
                    <BounceEase EasingMode="EaseInOut" Bounciness="5" />
                </chartingToolkit:BarSeries.TransitionEasingFunction>
                <chartingToolkit:BarSeries.DataPointStyle>
                    <Style TargetType="Control">
                        <Setter Property="Background" Value="Red"/>
                    </Style>
                </chartingToolkit:BarSeries.DataPointStyle>
            </chartingToolkit:BarSeries>
            <chartingToolkit:Chart.Axes>
                <chartingToolkit:LinearAxis Title="Types owned"  Orientation="X" Minimum="0" Maximum="300" 
                  Interval="10" ShowGridLines="True"  FontStyle='Italic'/>
            </chartingToolkit:Chart.Axes>
        </chartingToolkit:Chart>
    
    </Grid>
    

    代码落后

    public class MyClass : DependencyObject
        {
            public string Name { get; set; }
            public Double Value {
                get { return (Double)GetValue(myValueProperty); } 
                set{SetValue(myValueProperty,value);} 
            }
            public static readonly DependencyProperty myValueProperty =
                DependencyProperty.Register("Value", typeof(Double), typeof(MyClass), null);
        }
    
    public MainPage()
            {
                InitializeComponent();
                //Get the data
                IList<MyClass> l = this.GetData();
                //Get a reference to the SL Chart
    
            MyChart.DataContext = l.OrderBy(e => e.Value);
            //Find the highest number and round it up to the next digit
            DispatcherTimer myDispatcherTimer = new DispatcherTimer();
            myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 5, 0); // 100 Milliseconds 
            myDispatcherTimer.Tick += new EventHandler(Each_Tick);
            myDispatcherTimer.Start();
    
        }
        public void Each_Tick(object o, EventArgs sender)
        {
            ((BarSeries)MyChart.Series[0]).DataContext = GetData();
        }
    
        private IList<MyClass> GetData()
        {
            Random random = new Random();
    
            return new List<MyClass>()
            {
                new MyClass() {Name="Bob Zero",Value=(random.NextDouble() * 100.0)},
                 new MyClass() {Name="Bob One",Value=(random.NextDouble() * 100.0)},
                  new MyClass() {Name="Bob Two",Value=(random.NextDouble() * 100.0)},
                   new MyClass() {Name="Bob Three",Value=(random.NextDouble() * 100.0)}
            };
        }
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   AnthonyWJones    15 年前

    名称bounceEase是指动画值随动画时间变化的方式。这个 BounceEase 改变值,就像你想象的球弹跳一样。文档中的图表描述了它。

    关键是,最终动画只是改变了一个值,他们并不真正理解改变值的视觉效果是什么。在这种情况下,要设置动画的值是数据点不透明度。因此,随着弹跳的放松,它看起来有点褪色,然后逐渐消失,然后逐渐褪色,以此类推,直到它完全褪色。

    为数据点创建一个新的模板以获得所需的效果还需要相当多的工作。