I'm currently testing out IG's DataVisualizaion and Charting tools, xamDataChart looks very nice, and I'm wondering if it can emulate, in xaml, a sort of DataTemplate wrapper for a Series (Line particularly). I've had success with a different Charting toolkit with an external wrapper class, and it's code looked something like this:
<multiChart:MultiChart> <multiChart:MultiChart.SeriesTemplate> <DataTemplate> <chartingToolkit:LineSeries /> </DataTemplate> </multiChart:MultiChart.SeriesTemplate> </multiChart:MultiChart>
The DataTemplate's the crucial part, as I do not know how many series I'll need to render until runtime. I don't see any kind of DataTemplate in the XamDataChart class, would there be another way to achieve this kind of behavior?
Hi,
Please see this post.
http://community.infragistics.com/forums/p/40011/242380.aspx#242380
Its possible it may need a small adjustment for the WPF version due to some different ways that DataContext is handled. Let me know if you have any problems or questions. I'll try to test this out later today myself and see if it needs any WPF adjustments.
We have been considering adding this feature natively. If you are interested in it, you could make a feature request to lodge your vote for it.
Hope this helps!
-Graham
The version I linked is a bit complicated, but very flexible, because it does everything with attached properties. You could also approach it with a just wrapper class instead which may simplify some things, but decrease the flexibility an amount.
That was a fast reply, thanks so much. I've been studying up on the Infragistics object model included in the trial and so far can get a decent XamDataChart working, but I'm struggling a bit with the sample you provided. Is that sample complete? I've tried creating a new project, adding a MainPage UserControl and copying your code verbatim (the first two code blocks - the first xaml and the control/seriesbinding classes). However, without changing anything it doesn't display any data. It builds fine, and I can see some binding is working as it does break on the get of the TestDataItem's value property, but the chart comes up blank. What am I missing?
As I feared it may need a few adjustments for WPF, I'll get back to you.
WPF works differently in some binding aspects compared to Silverlight. To get the linked sample to work for WPF, adjust your xaml like so:
<ig:XamDataChart Name="xamDataChart1" > <ig:XamDataChart.Axes> <ig:CategoryXAxis x:Name="xAxis" ItemsSource="{Binding ElementName=xamDataChart1, Path=Series[(System:Int32)0].ItemsSource}" Label="{}{Label}"/> <ig:NumericYAxis x:Name="yAxis" /> </ig:XamDataChart.Axes> <local:SeriesBinder.BindingInfo> <local:SeriesBindingInfo ItemsSource="{Binding}"> <local:SeriesBindingInfo.SeriesTemplate> <DataTemplate> <ig:LineSeries ItemsSource="{Binding Item.Data}" ValueMemberPath="{Binding Item.ValueMemberPath}" XAxis="{Binding Path=Owner.Axes[(System:Int32)0]}" YAxis="{Binding Path=Owner.Axes[(System:Int32)1]}" > </ig:LineSeries> </DataTemplate> </local:SeriesBindingInfo.SeriesTemplate> </local:SeriesBindingInfo> </local:SeriesBinder.BindingInfo> </ig:XamDataChart>
Let me know if this helps.
Hello,
I try to implement XamDataChart with WPF and your series binding solution like this :
<igCDA:XamDataChart Name="chartOverview2" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left"
Background="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GroupBox}, AncestorLevel=1},Path=Tag}" Width="500" Height="400"
>
<igCDA:XamDataChart.Axes>
<igCDA:CategoryDateTimeXAxis x:Name="xAxis" ItemsSource="{Binding SeriesCollection[1].DataSource, Mode=OneWay}" DateTimeMemberPath="Date" Label="{}{Date:MMM}" />
<igCDA:NumericYAxis x:Name="yAxis" MinimumValue="{Binding CurrentPeriod.MinTwrPerformance}" MaximumValue="{Binding CurrentPeriod.MaxTwrPerformance}"/>
</igCDA:XamDataChart.Axes>
<!--<igCDA:XamDataChart.Series>
<igCDA:LineSeries XAxis="{Binding ElementName=xAxis, Mode=OneWay}"
YAxis="{Binding ElementName=yAxis, Mode=OneWay}"
ItemsSource="{Binding SeriesCollection[1].DataSource, Mode=OneWay}"
Title="Test"
MarkerType="None"
ValueMemberPath="TwrPerformance"
TransitionDuration="0"
Brush="#FF9966" />
ItemsSource="{Binding SeriesCollection[0].DataSource, Mode=OneWay}"
</igCDA:XamDataChart.Series>-->
<core:SeriesBinder.BindingInfo>
<core:SeriesBindingInfo ItemsSource="{Binding SeriesCollection}">
<core:SeriesBindingInfo.SeriesTemplate>
<DataTemplate>
<igCDA:LineSeries
XAxis="{Binding Path=Owner.Axes[0]}"
YAxis="{Binding Path=Owner.Axes[1]}"
ItemsSource="{Binding DataSource, Mode=OneWay}"
</DataTemplate>
</core:SeriesBindingInfo.SeriesTemplate>
</core:SeriesBindingInfo>
</core:SeriesBinder.BindingInfo>
</igCDA:XamDataChart>
When I try with the "SeriesBinder" nothing is displayed on the creen (blank chart), but if I reactivate normal declarations of Series (in comment in the examples) it works.
Is there an error in my code ?
Thanks
Steph
Steph,
WPF has a couple differences with its binding engine that affect this sample. Specifically with the order in which it evaluates indexers. You need to perform a cast on the integers in the indexers to prevent them from being treated as string indexers. See: http://community.infragistics.com/forums/p/50183/264477.aspx#264477
I finally figured out what's going on..... I went through your code and find out you encapsulate ItemsSource in an Item object.... I just changed my code like that and everything works fine :
ItemsSource="{Binding Item.DataSource, Mode=OneWay}"
Thanks for you support Graham.
One more thing,
if I debug, I can see in my chart the right number of series but it's like the binding doesn't work for datapoints (ItemsSource is null).......
No errors, Axis are well drawn with right minimum and maximum values, just LineSeries don't appear.
If I use the code below instead of the SeriesBinder, it works :
The thing is I don't have a static collection of LineSeries.....
Did you also add the namespace binding for System, discussed further down the page? Are you receiving any binding errors in the log?
Thanks Graham for your answer !
I modified my code like that but nothing changed :
XAxis="{Binding Path=Owner.Axes[(System:Int32)0]}"
YAxis="{Binding Path=Owner.Axes[(System:Int32)1]}"