如何绑定 ObservableCollection到图表
我在图表绑定方面遇到了一个小问题。 WPF 工具包折线图是否可以有动态的系列数?
我发现了很多如何手动执行此操作的示例。
例如,如果我有类似的东西:
<chartingToolkit:Chart Grid.ColumnSpan="4" Grid.Row="3" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Name="chart_Distribution" Title="Chart Title">
和模型类似:
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));
}
}
如何将我的图表绑定到 ObservableCollection? 是否可以?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下博客文章对此有一个很好的解决方案:
http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/351/Silverlight-Charts-Binding-multiple-Series.aspx
科林·E.
There is a good solution to this on the following blog post:
http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/351/Silverlight-Charts-Binding-multiple-Series.aspx
Colin E.