I´ve got the following code:
private void LoadPieChartData()
{
LinkedList<String> kostenstellen = rep.GetKostenstellen();
for (int i = 0; i < kostenstellen.Count; i++)
{
((ColumnSeries)PieChart.Series[i]).ItemsSource = new KeyValuePair<string, double>[]{
new KeyValuePair<string,double>(kostenstellen.ElementAt(i), i+1)
};
}
}
}
My Xaml looks like this:
<DVC:Chart HorizontalAlignment="Left" Margin="625,44,0,0" Name="PieChart" VerticalAlignment="Top" Height="276" Width="256" >
<DVC:Chart.Series>
<DVC:PieSeries Title="FirstPiece" ItemsSource="{Binding LoadPieChartData}" IndependentValueBinding="{Binding Path=Key}" DependentValueBinding="{Binding Path=Value}" />
<DVC:PieSeries Title="SecondPiece" ItemsSource="{Binding LoadPieChartData}" IndependentValueBinding="{Binding Path=Key}" DependentValueBinding="{Binding Path=Value}" />
</DVC:Chart.Series>
</DVC:Chart>
My problem is, that the i in the for-loop can be raise up to about 20. So, I would need about 20 PieSeries, to create them dynamic isn´t possible as I know.
How can I manage that?
If what you are trying to do is simply display a pie chart with several segments, all you have to do is bind a collection to a single
PieSeries‘sItemsSourceproperty:I used the following property:
And I get the following chart: