Reputation: 1111
I have a litle problem with Chart binding. Is it possible to have a dynamic number of series for a WPF toolkit line chart?
I found many examples how to do it manualy.
For example If I have something like:
<chartingToolkit:Chart Grid.ColumnSpan="4" Grid.Row="3" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Name="chart_Distribution" Title="Chart Title">
And Model like:
public class Test : BaseViewModel
{
private readonly ObservableCollection<LineSeries> _lineSeries = new ObservableCollection<LineSeries>();
public ObservableCollection<LineSeries> LineSeries
{
get { return _lineSeries; }
}
private void Test()
{
var collection = new ObservableCollection<RequestsInProcess>();
var collection2 = new ObservableCollection<RequestsInProcess>();
collection.Add(new RequestsInProcess(0, 4));
collection.Add(new RequestsInProcess(1, 1));
collection.Add(new RequestsInProcess(2, 4));
collection.Add(new RequestsInProcess(3, 3));
collection2.Add(new RequestsInProcess(0, 3));
collection2.Add(new RequestsInProcess(1, 2));
collection2.Add(new RequestsInProcess(2, 2));
collection2.Add(new RequestsInProcess(3, 1));
var lineseries1 = new LineSeries();
lineseries1.IndependentValuePath = "AmountOfRequests";
lineseries1.DependentValuePath = "Time";
lineseries1.Title = "Line series1";
lineseries1.ItemsSource = collection;
Charts.Add(lineseries1);
var lineseries2 = new LineSeries();
lineseries2.IndependentValuePath = "AmountOfRequests";
lineseries2.DependentValuePath = "Time";
lineseries2.Title = "Line series2";
lineseries2.ItemsSource = collection2;
Charts.Add(lineseries2);
collection2.Add(new RequestsInProcess(4, 4));
collection.Add(new RequestsInProcess(4, 4));
}
}
How can I Bind my chart to ObservableCollection? Is it possible?
Upvotes: 2
Views: 4428
Reputation: 70150
There is a good solution to this on the following blog post:
Colin E.
Upvotes: 3