2012-10-09 60 views
0

我有幾個複選框(其中content =數據庫中的名稱)。在metchod checkbox_checked中,試圖將ColumnSeries添加到wpf Chart,但仍然出現錯誤: 「對象引用未設置爲對象的實例。」添加ItemsSource到wpf圖表中的ColumnSeries時出錯

這裏是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

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

相關問題