0

我有几个复选框(其中内容 = 数据库中的名称)。在 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());

任何人都可以帮忙吗?:)

4

1 回答 1

1

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

于 2012-10-09T14:37:50.707 回答