Hi,
I can get XamWebChart to graph data using the following C# code:
Series PullSeries = new Series { Label = "pulls", ChartType = ChartType.Line, DataMapping = "label=SDate;value=Pulls;", DataSource = e.Result }
PullsChart.Series.Add(PullandDeadsSeries);
e being = OnFeed_SL.ServiceReference1.GetPullsAndDeadsSTRDateCompletedEventArgs
To do the above what would be a code example in XAML... What I am trying to do is the graph using BLEND to develop with and let BLEND connect up to the data source using XAML.
THANKS
Keith
If that code behind is in your window or usercontrol class, set this.DataContext equal to the e.Result when the web service call returns, this has established the web service result as the data context for binding in the XAML for any children of the window/usercontrol.
Then your series can look like this in XAML:
<igChart:XamWebChart.Series>
<igChart:Series Label="pulls"
ChartType="Line"
DataSource="{Binding}"
DataMapping="Label = SDate; Value = Pulls"/>
</igChart:XamWebChart.Series>
This help?
-Graham
the handler in the code behind:
void _client_GetPullsAndDeadsSTRDateCompleted(object sender,
OnFeed_SL.ServiceReference1.GetPullsAndDeadsSTRDateCompletedEventArgs e)
{
DataContext = e.Result;
}
Basically, you need some code behind in this case to establish the data context because the WCF service requires you to execute and respond to an asynchronous call in order to retrieve the data. You could wrap a class around the service and try to make the call execute synchronously if you wanted to just instantiate the class in the Xaml and bind to it.
I misspoke when I said that you could try to make the call synchronous, I've remembered it isnt a good idea to make the UI thread halt in Silverlight if it could be waiting a while. Here's another option you have (other than setting the datacontext in the window/usercontrol code behind), which you may find useful:
public class ChartDataFetcher
: DependencyObject
private ChartDataService.ChartDataServiceClient _client =
new ChartDataService.ChartDataServiceClient();
private ObservableCollection<Person> _data;
private object _dataLock = new object();
public ChartDataFetcher()
_client.GetDataCompleted +=
new EventHandler<ChartDataService.GetDataCompletedEventArgs>(_client_GetDataCompleted);
_client.GetDataAsync();
public DependencyProperty ChartDataProperty =
DependencyProperty.Register("ChartData", typeof(ObservableCollection<Person>),
typeof(ChartDataFetcher),
new PropertyMetadata(
new ObservableCollection<Person>() { new Person() { Name = "test", ShoeSize = 10 } }));
public ObservableCollection<Person> ChartData
get
return (ObservableCollection<Person>)GetValue(ChartDataProperty);
set
SetValue(ChartDataProperty, value);
void _client_GetDataCompleted(object sender, ChartDataService.GetDataCompletedEventArgs e)
ChartData = e.Result;
It basically calls the service when constructed and puts the asynchronous results in a dependency property, which allows you to do something like this:
<UserControl.Resources>
<local:ChartDataFetcher x:Key="Fetcher" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<igChart:XamWebChart>
DataSource="{Binding ChartData, Source={StaticResource Fetcher}}"
DataMapping="Label = Name; Value = ShoeSize"/>
</igChart:XamWebChart>
</Grid>
And in this case the window/usercontrol doesn't need any code behind, but it requires creating that proxy class around the service. Notice this proxy can return some sample results immediately (like above) while its waiting for the web service to return. I've noticed the category axis on the chart doesn't seem to want to display properly unless you do this, but I'm not sure yet whether this is a bug or something missing in the setup.