在wpf图表中将ItemsSource添加到ColumnSeries时出错

时间:2012-10-09 14:08:34

标签: wpf charts wpftoolkit toolkit

我有几个复选框(其中content =来自数据库的名称)。在metchod checkbox_checked我试图将ColumnSeries添加到wpf图表,但仍然收到错误: “对象引用未设置为对象的实例。”

这是xaml代码:

      <DVC:Chart Canvas.Top="80" Canvas.Left="10" Name="wykres1"  Background="LightSteelBlue">

</DVC:Chart>

代码隐藏:

CheckBox c = (CheckBox)sender;

            ColumnSeries b = new ColumnSeries();
            b.Title = c.Content.ToString();
            b.ItemsSource = null;
            b.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),
                    new KeyValuePair<string, int>("Team Leader", 6),
                    new KeyValuePair<string, int>("Project Leader", 10),
                    new KeyValuePair<string, int>("Developer", 4) };
            wykres1.Series.Add(b);

            categoryList.Add(c.Tag.ToString());

任何人都可以提供帮助? :)

1 个答案:

答案 0 :(得分:1)

现在工作。解决方案是:       ColumnSeries b = new ColumnSeries {Title = c.Content.ToString(),IndependentValueBinding = new Binding(“Key”),DependentValueBinding = new Binding(“Value”)};

相关问题