Like the structure behind point is
public class SimpleDataPoint {
public static int Count = 4; //Some restiction
public DateTime xAxis { get; set; } public float[] yAxis { get; set; }}And I am trying to create axis and bind dynamically as for (int i = 0; i < SimpleDataPoint.Count; i++) { LineSeries xmSeries = new LineSeries(); xmSeries.ValueMemberPath = "{yAxis[" +i.ToString() + "]}"; xmSeries.XAxis = xmXAxis; ..... }This does not seem to work. What should be ValueMemberPath. Or is there someother way
}
And I am trying to create axis and bind dynamically as
for (int i = 0; i < SimpleDataPoint.Count; i++) { LineSeries xmSeries = new LineSeries(); xmSeries.ValueMemberPath = "{yAxis[" +i.ToString() + "]}"; xmSeries.XAxis = xmXAxis; ..... }This does not seem to work. What should be ValueMemberPath. Or is there someother way
The member paths do no currently support indexers like a standard Silverlight binding. The upside is that they are much more efficient than the standard bindings when you are dealing with mass amounts of data. If the indexer support would be useful for your scenario I would suggest making a feature request.
In the meantime I would suggest creating a seperate property per value which you want to plot, or a seperate collection of values per series. You could even create an object that automatically turns your source collection into multiple collections to bind to each separate series.
Does this help?
-Graham
By That way I cannot create dynamic number of chart lines. What do I have do to a feature request?
Here's one way of going about it:
public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); var testData = new TestSimpleDataPointCollection(); chart.BindTimeSeriesCollection( TimeSeriesData.ToTimeSeriesCollection( testData)); } } public static class Extensions { public static void BindTimeSeriesCollection(this XamDataChart chart, TimeSeriesCollection coll) { if (coll.Count < 1) { return; } var xAxis = new CategoryDateTimeXAxis(); xAxis.ItemsSource = coll[0]; xAxis.DateTimeMemberPath = "Time"; xAxis.Label = "{Time}"; var yAxis = new NumericYAxis(); chart.Axes.Clear(); chart.Axes.Add(xAxis); chart.Axes.Add(yAxis); chart.Series.Clear(); foreach (var data in coll) { var line = new LineSeries(); line.ItemsSource = data; line.ValueMemberPath = "Value"; line.XAxis = xAxis; line.YAxis = yAxis; chart.Series.Add(line); } } } public class TimeSeriesCollection : ObservableCollection<TimeSeriesData> { } public class TimeSeriesData : ObservableCollection<TimeSeriesDataItem> { public static TimeSeriesCollection ToTimeSeriesCollection(List<SimpleDataPoint> simplePoints) { int count = SimpleDataPoint.Count; var coll = new TimeSeriesCollection(); for (int i = 0; i < count; i++) { coll.Add(new TimeSeriesData()); } foreach (var point in simplePoints) { for (int i = 0; i < count; i++) { coll[i].Add( new TimeSeriesDataItem() { Time = point.xAxis, Value = point.yAxis[i] }); } } return coll; } } public class TimeSeriesDataItem { public DateTime Time { get; set; } public double Value { get; set; } } public class SimpleDataPoint { public static int Count = 4; //Some restiction public DateTime xAxis { get; set; } public float[] yAxis { get; set; } } public class TestSimpleDataPointCollection : List<SimpleDataPoint> { public TestSimpleDataPointCollection() { for (int i = 0; i < 20; i++) { Add(new SimpleDataPoint() { xAxis = DateTime.Now.AddDays(i * -1), yAxis = new float[] { i, i + 1, i + 2, i + 3 } }); } } }
Let me know if this helps.