I have a XamWebChart with the following series object,
<igChart:XamWebChart.Series> <igChart:Series ChartType="Line" Fill="#FF81A938" StrokeThickness="2" Animation="{StaticResource DataPointAnimation}"> <igChart:Series.Marker> <igChart:Marker Foreground="#FF666666" MarkerSize=".7" Type="Circle" /> </igChart:Series.Marker> <igChart:Series.DataPoints> <igChart:DataPoint x:Name="dp1" Label="2000" Value="686" /> <igChart:DataPoint x:Name="dp2" Label="2001" Value="641" /> <igChart:DataPoint x:Name="dp3" Label="2002" Value="620" /> <igChart:DataPoint x:Name="dp4" Label="2003" Value="592" /> <igChart:DataPoint x:Name="dp5" Label="2004" Value="570" /> </igChart:Series.DataPoints> </igChart:Series> </igChart:XamWebChart.Series>
In the code behind, I'm creating a storyboard like,
Storyboard sb = new Storyboard();
foreach (DataPoint dp in ChartPhoneUsage.Series[0].DataPoints) { DoubleAnimation db = new DoubleAnimation(); db.To = (i + 1) * 100; db.Duration = new TimeSpan(0, 0, 1); Storyboard.SetTarget(db, dp); Storyboard.SetTargetProperty(db, new PropertyPath(DataPoint.ValueProperty)); sb.Children.Add(db); i++; } sb.Begin();
When I run, I see the runtime exception AG_E_BAD_PROPERTY. [Refer attachement] I'm seeing it 5 times.
When I remove the loop or modify the loop condition to run the animation on only one datapoint, but not on all the datapoints, then its working.
To the best of my knowledge, you would not be able to animate all at once. However, I believe you can make the duration of the animation to a value close to 0, so that it looks that this is done immediately.
Thank you for the reply, Alex.
I got it worked for Bubble and Scatter Charts, which use ChartParameters. I was able to change the value of chart parameter, using a storyboard animation.
Will try the above approach. But I guess it'll not animate all the datapoints in parallel...!!
Is there any other way I achieve the result such that all the datapoints start and finish at same time??
The error you are getting appears to be because different animations are trying to modify the data points at the same time. What you could do is to start the animations one after another. Here is some sample code that our developers recommended
private List<Storyboard> storyboards = new List<Storyboard>();
...
private void Button_Click(object sender, RoutedEventArgs e) { foreach (DataPoint dp in xamWebChart1.Series[0].DataPoints) { Storyboard sb = new Storyboard(); DoubleAnimation db = new DoubleAnimation(); db.To = 100; db.Duration = new TimeSpan(0, 0, 1);
Storyboard.SetTarget(db, dp); Storyboard.SetTargetProperty(db, new PropertyPath(DataPoint.ValueProperty)); sb.Children.Add(db);
storyboards.Add(sb); sb.Completed += new EventHandler(sb_Completed); }
storyboards[0].Begin(); }
void sb_Completed(object sender, EventArgs e) { int index = storyboards.IndexOf(sender as Storyboard);
index++;
if (index < storyboards.Count) { storyboards[index].Begin(); } }
Hi Alex,
Its true, that I can not set 'To', if I'm using a Infragistics Animation. But I'm trying to use the Silverlight DoubleAnimation, not the Infragistics Animation.
So if I can not set 'To', how can I animate the datapoint to change its value to some other?. Say from 10 to 100.
My requirement is to change the values of datapoints at runtime, using animation. Please help.
Also, for your information, I can able to change the datapoint value, using 'To' in DoubleAnimation, if its applied on single datapoint. Only when I tried that in a loop, I'm getting the error shown in previous post.
Hello,
You would not be able to affect the from/to properties of the Double Animation. What you can set in these animations are the begin time, duration, acceleration ration, deceleration ratio properties. The rest is handled by the XamWebChart. You can see more information on Animations in the XamWebChart in this help article here :
http://help.infragistics.com/NetAdvantage/DV/2009.2/CLR3.5/?page=SL_DV_xamWebChart_Animation_Overview.html