现在,我有这个代码:
xaml:
<DVC:Chart Name="MyChart" Background="LightBlue" Margin="10">
<DVC:Chart.Series>
<DVC:BarSeries Title="Sumele"
IndependentValueBinding="{Binding Path=Key}"
DependentValueBinding="{Binding Path=Value}">
</DVC:BarSeries>
</DVC:Chart.Series>
</DVC:Chart>
xaml.cs:
using System.Windows.Controls.DataVisualization.Charting;
private void LoadBarChartData()
{
((BarSeries)MyChart.Series[0]).ItemsSource =
new KeyValuePair<string, int>[]{
new KeyValuePair<string,int>("Project Manager", 12),
new KeyValuePair<string,int>("CEO", 25),
new KeyValuePair<string,int>("Software Engg.", 5)
}
有没有一种方法可以以某种方式绑定,例如LIST?或DataTable?这将包含我在上面写的所有信息。。。
((BarSeries)MyChart.Series[0]).ItemsSource=(此处)
感谢
好吧,我找到了解决方案,如何创建该对象并使用for循环插入集合
int t = 10;
KeyValuePair<string, int>[] cp = new KeyValuePair<string, int>[t];
for (int i = 0; i < 10; i++)
{
cp[i] = new KeyValuePair<string, int>("Project Manager", i);
}
((ColumnSeries)MyChart.Series[0]).ItemsSource = cp;