2
votes

I am trying to display a Pie Chart in WPF using the WPF Toolkit (System.Windows.Controls.DataVisualization.Toolkit.dll)

The Chart itself is created by doind this in my XAML:

<DVC:Chart BorderThickness="0" Title="Arbeitsverteilung" Grid.Column="0" Grid.Row="0" Background="Teal" x:Name="workDist" >
  <DVC:Chart.Series>
    <DVC:PieSeries 
      IndependentValuePath="Key"
      DependentValuePath="Value"
      VerticalAlignment="Top"
      HorizontalAlignment="Stretch"/>
  </DVC:Chart.Series>
</DVC:Chart>

and I set the DataSource with the following Method:

private void LoadData()
{
  ((PieSeries)workDist.Series[0]).ItemsSource =
    new KeyValuePair<string, int>[] {
      new KeyValuePair<string, int> ("Mario", 12),
      new KeyValuePair<string, int> ("Ahner", 14)};
}

That seems to work pretty well with one problem: It only displays the legend for the chart but not the chart itself:

screenshot

I've already read a few tutorials but everyone did it exactly like I did and it worked fine.

Would be nice if someone could help me!

1

1 Answers

2
votes

Take out the top vertical alignment:

    <DVC:Chart BorderThickness="0" Title="Arbeitsverteilung" Grid.Column="0" Grid.Row="0" Background="Teal" x:Name="workDist" >
        <DVC:Chart.Series>
            <DVC:PieSeries 
                IndependentValuePath="Key"
                DependentValuePath="Value"
                HorizontalAlignment="Stretch"
                />
        </DVC:Chart.Series>
    </DVC:Chart>

enter image description here