Charts Itemscontrol中的WPFToolkit图表

Charts Itemscontrol中的WPFToolkit图表,charts,wpftoolkit,itemscontrol,lineseries,Charts,Wpftoolkit,Itemscontrol,Lineseries,好的,这就是我要做的。我需要在一个图表控件中包含多个列表图表。在这篇文章中使用Sheog的答案很容易: 问题是在运行时之前我不知道需要多少图表。因此,我的想法是将其放入items控件中,并将数据模板设置为一个LineSeries,如下所示: <ItemsControl x:Name="pieChart"> <ItemsControl.ItemsPanel>

好的,这就是我要做的。我需要在一个图表控件中包含多个列表图表。在这篇文章中使用Sheog的答案很容易:

问题是在运行时之前我不知道需要多少图表。因此,我的想法是将其放入items控件中,并将数据模板设置为一个LineSeries,如下所示:

                       <ItemsControl x:Name="pieChart">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <chartingToolkit:Chart DataContext="{Binding}"  Title="Pie Series Demo" Margin="0" Background="#FF48474B" Height="400"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" IsSelectionEnabled="True" />
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>

我的数据是:

        List<KeyValuePair<string, int>> valueList = new List<KeyValuePair<string, int>>();
        valueList.Add(new KeyValuePair<string, int>("Developer", 60));
        valueList.Add(new KeyValuePair<string, int>("Misc", 20));
        valueList.Add(new KeyValuePair<string, int>("Tester", 50));
        valueList.Add(new KeyValuePair<string, int>("QA", 30));
        valueList.Add(new KeyValuePair<string, int>("Project Manager", 40));


        List<KeyValuePair<string, int>> valueList2 = new List<KeyValuePair<string, int>>();
        valueList2.Add(new KeyValuePair<string, int>("Developer", 40));
        valueList2.Add(new KeyValuePair<string, int>("Misc", 40));
        valueList2.Add(new KeyValuePair<string, int>("Tester", 40));
        valueList2.Add(new KeyValuePair<string, int>("QA", 40));
        valueList2.Add(new KeyValuePair<string, int>("Project Manager", 20));

        var dataSourceList = new List<List<KeyValuePair<string, int>>>();
        dataSourceList.Add(valueList);
        dataSourceList.Add(valueList2);

        pieChart.DataContext = dataSourceList;
List valueList=新列表();
添加(新的KeyValuePair(“开发者”,60));
添加(新的KeyValuePair(“Misc”,20));
添加(新的KeyValuePair(“Tester”,50));
添加(新的KeyValuePair(“QA”,30));
添加(新的KeyValuePair(“项目经理”,40));
List valueList2=新列表();
valueList2.添加(新的KeyValuePair(“开发者”,40));
valueList2.添加(新的KeyValuePair(“Misc”,40));
valueList2.添加(新的KeyValuePair(“Tester”,40));
valueList2.添加(新的KeyValuePair(“QA”,40));
valueList2.添加(新的KeyValuePair(“项目经理”,20));
var dataSourceList=新列表();
数据源列表。添加(值列表);
dataSourceList.Add(valueList2);
pieChart.DataContext=dataSourceList;
我的感觉是,问题出在我的数据绑定中的某个地方,但我对它的了解还不够,无法排除故障

我发现了这个:

事实上,它确实工作得很好,但我仍然想知道如何在XAML中实现这一点

谢谢,