gpt4 book ai didi

c# - 如何将 ObservableCollection 绑定(bind)到图表

转载 作者:行者123 更新时间:2023-11-30 22:42:16 24 4
gpt4 key购买 nike

我对图表绑定(bind)有一点疑问。是否可以为 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));

}
}

如何将我的图表绑定(bind)到 ObservableCollection?可能吗?

最佳答案

关于c# - 如何将 ObservableCollection<LineSeries> 绑定(bind)到图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4488057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com