2012-04-11 67 views
0

我正在嘗試使用WPF餅圖。問題是隻有最後一片保持顯示。我可以看到所有切片都顯示並且立即隱藏,除了最後一個。任何想法 ?WPF餅圖 - 切片不顯示在圖表上

<Window x:Class="ScrumApp01.WindowGraphique" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
    xmlns:DV="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
    xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
    xmlns:local="clr-namespace:ScrumApp01" 
    Title="Fenêtre graphiques SCRUM" Height="674" Width="1216" ResizeMode="CanResizeWithGrip" Name="GraphicScrum01"> 

<DVC:Chart Margin="25,268,0,0" Title="Pointe de tarte" LegendTitle="Les datas" Background="LightSteelBlue" HorizontalAlignment="Left" VerticalAlignment="Top" Height="324" Width="307"> 
<DVC:PieSeries Title="Les datas en tarte" Name="Tarte2" 
    ItemsSource="{StaticResource FruitCollection2}" 
    IndependentValueBinding="{Binding Path=sss}" 
    DependentValueBinding="{Binding Path=nnn}" > 
</DVC:PieSeries> 

private void button3_Click(object sender, RoutedEventArgs e) 
{ 
    FruitCollection2 fff = new FruitCollection2(); 
    fff.Clear(); 
    fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[0], bbb = 1, ddd = 10, sss = "Item a" }); 
    fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[1], bbb = 2, ddd = 9, sss = "Item b" }); 
    fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[2], bbb = 3, ddd = 11, sss = "Item c" }); 
    fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[3], bbb = 1, ddd = 14, sss = "Item d" }); 
    fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[4], bbb = 4, ddd = 7, sss = "Item e" }); 
    fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[5], bbb = 5, ddd = 1, sss = "Item f" }); 
    fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[6], bbb = 6, ddd = 7, sss = "Item g" }); 
    fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[7], bbb = 3, ddd = 6, sss = "Item h" }); 
    fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[8], bbb = 3, ddd = 7, sss = "Item i" }); 
    fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[9], bbb = 4, ddd = 5, sss = "Item j" }); 


    this.Tarte2.ItemsSource = fff; 

} 
+0

什麼是DVC命名空間?你用的是哪張餅圖? – ColinE 2012-04-11 05:04:27

+0

我編輯了代碼並添加了標題 – user1325596 2012-04-11 06:09:56

+0

是「nnn」,「sss」屬性還是字段?如果它的字段綁定不起作用。 – AndrewS 2013-06-07 15:59:38

回答

0

你在你的圖表設置的ItemsSource的方式很奇怪。這樣做,這樣應該工作:

在定義的類sss通過{Binding Path=sss}(基本上DVC的DataContext的:PieSeries將)被稱爲,聲明這個屬性:

private ObservableCollection<Fruit02> mFff = new ObservableCollection<Fruit02>(); 
public ObservableCollection<Fruit02> fff 
{ 
    get { return mFff; } 
} 

然後綁定您的DVC:PieSeries將的ItemSource像這樣:

<DVC:PieSeries Title="Les datas en tarte" Name="Tarte2" 
    ItemsSource="{Binding Path=fff}" 
    IndependentValueBinding="{Binding Path=sss}" 
    DependentValueBinding="{Binding Path=nnn}" > 
</DVC:PieSeries> 

然後在點擊處理,不創建一個新的集合,只需要修改現有的一個:

private void button3_Click(object sender, RoutedEventArgs e) 
    { 
     fff.Clear(); 
     fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[0], bbb = 1, ddd = 10, sss = "Item a" }); 
     fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[1], bbb = 2, ddd = 9, sss = "Item b" }); 
     fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[2], bbb = 3, ddd = 11, sss = "Item c" }); 
     fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[3], bbb = 1, ddd = 14, sss = "Item d" }); 
     fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[4], bbb = 4, ddd = 7, sss = "Item e" }); 
     fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[5], bbb = 5, ddd = 1, sss = "Item f" }); 
     fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[6], bbb = 6, ddd = 7, sss = "Item g" }); 
     fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[7], bbb = 3, ddd = 6, sss = "Item h" }); 
     fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[8], bbb = 3, ddd = 7, sss = "Item i" }); 
     fff.Add(new Fruit02 { nnn = this.data001.listeNombres03[9], bbb = 4, ddd = 5, sss = "Item j" }); 
    } 

假設您的DataContext設置正確,並且您的餅圖控件正確實施,這應該可以工作。

+0

好吧..同樣的結果......我想我會放棄! :) – user1325596 2012-04-12 03:33:38