gpt4 book ai didi

wpf - 如何在 wpf 工具包中向折线图中动态添加更多折线系列?

转载 作者:行者123 更新时间:2023-12-02 22:11:23 24 4
gpt4 key购买 nike

我正在尝试使用 wpf 工具包图表线,我需要在图表中有不止一行,但我不知道该怎么做我需要在 c# 中动态地执行它。在程序中,我不知道我需要多少图表以及每个图表中有多少行,这是我无法在 XAML 中做到的方式...

for (int j = 0; j < 4; j++) //its just so i cant check it
{
ColumnDefinition cd = new ColumnDefinition();
myGrid.ColumnDefinitions.Add(cd);

Chart chart1 = new Chart();
LineSeries lineChart = new LineSeries();
chart1.Height = 200;
chart1.Width = 300;
chart1.Title = (j);

//((LineSeries)chart1.Series[0]).ItemsSource = valueList;

lineChart.DependentValuePath = "Value";
lineChart.IndependentValuePath = "Key";
lineChart.ItemsSource = valueList;
lineChart.IsSelectionEnabled = true;
chart1.Series.Add(lineChart);
lineChart.ItemsSource = valueList1;
chart1.Series.Add(lineChart); <---

myGrid.Children.Add(chart1);
Grid.SetColumn(chart1, (j));
Grid.SetRow(chart1, 0);

}

我试过了,但是没用...

请帮忙!:(

最佳答案

XAML:

<chartingToolkit:Chart Name="lineChart" />

代码隐藏:

private void showChart(List<KeyValuePair<string, int>> valueList)
{
LineSeries lineSeries1 = new LineSeries();
lineSeries1.Title = "Title";
lineSeries1.DependentValuePath = "Value";
lineSeries1.IndependentValuePath = "Key";
lineSeries1.ItemsSource = valueList;
lineChart.Series.Add(lineSeries1);
}

您可以将 valueList 定义为: List<KeyValuePair<string, int>> valueList = new List<KeyValuePair<string, int>>();

并插入所需的值作为 valueList.Insert(0, new KeyValuePair<string, int>(key, value));

关于wpf - 如何在 wpf 工具包中向折线图中动态添加更多折线系列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15253576/

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