How can I bind the XamWebChart to a SeriesCollection. I'm getting data from a service, in Xml format, containing the values and styles for few series' with several datapoints.
I created SeriesCollection in my ViewModel. Now how should I bind my view to make it use the SeriesCollection to draw graphs.
You will want to check this post to get you started:
https://ko.infragistics.com/community/forums/f/ultimate-ui-for-wpf/38169/series-binding-in-xaml-custom-attached-property
Unfortunately there seems to be a problem with the forums this morning, so this post isn't currently accessible.
-Graham
Its back up. So you can check that out if you want. But the exampl linked is really more for if you want to create the series based on a template in Xaml. If you are already creating the series collection in your View Model have you tried just binding it to the chart?
I.E if the property holding the SeriesCollection on your DataContext is called Series. Have you tried
<XamWebChart Series="{Binding Series} ...
Hi there!
Very nice post, and very useful as well.
I was wondering if the DataMapping defined in the code above can be used for Indexed properties of dynamically generated objects as well. I tried but it did not work.
Is it possible to have dynamically generated objects, with indexed properties being used for binding?
Thanks,
If you are talking about IDictionary indexed properties. I believe the chart can do this now in version 11.2. You can do something like this ValueMemberPath="SomeDictionary[SomeKey]" is that the kind of thing you are referring to?
Here is the Dynamic object I have used in my code:
public class DynamicObject
{
Dictionary<string, object> properties = new Dictionary<string, object>();
public object this[string name]
get
if (properties.ContainsKey(name))
return properties[name];
}
return null;
set
properties[name] = value;
Hi,
I thought you were talking about xamDataChart. The xamWebChart does not support string indexers for the series data. You could try the 11.2 xamDataChart or create a type with named properties for the xamWebChartData.
Alternatively you could create an adapter that looks at your dynamicObjects and creates a collection of DataPoint and adds those directly to the series rather than using DataMapping.
I am not sure if I could follow the approach you mentioned about using adapter instead of using DataMapping. If any example code can be provided, I guess that should help.Also, what I need in essence is to use MVVM pattern and have different types of charts e.g., Bar, Column, Line, Pie etc. generated. The data to be used for binding is going to have variable no. of fields, so the collection I end up with after receiving response from service is a collection of dynamic objects, with indexed properties. This is the reason I cannot go for named properties. My question is will it be possible to implement charts as mentioned in above para with MVVM approach, OR I will be required to have code-behind approach mixed with MVVM for creating charts dynamically?
There may not be a way to use indexed properties currently with the labels. I would suggest making a feature request.
The xamWebChart does not support indexed properties.
In either case, your work would be easier if you bound types with named properties against the chart. If this is not possible, I'd recommend making the above feature request.
Also, when I am trying to use indexed properties with XamDataChart, I am able to use indexed properties in "ValueMemberPath", but unable to use them in Axis Labels. Can you please help me on that as well?
-Vikram