Emmet
Emmet

Reputation: 209

How to create a Pie Chart with LiveCharts

I need help creating a (test) pie chart with LiveCharts. I am using this xaml code

<Grid>
<lvc:PieChart x:Name="myPieChart"/>
</Grid>

and then in code behind

LiveCharts.Wpf.PieSeries ps = new LiveCharts.Wpf.PieSeries
{
    Values = new LiveCharts.ChartValues<decimal> { 1, 3} 
};
myPieChart.Series.Add(ps);

But instead of getting one pie chart with 2 slices, I get 2 concentric pie charts, each with 1 complete slice only.

Upvotes: 0

Views: 3248

Answers (1)

Emmet
Emmet

Reputation: 209

Ok, I was able to get the job done by doing this

LiveCharts.SeriesCollection psc = new LiveCharts.SeriesCollection
{
    new LiveCharts.Wpf.PieSeries
    {
        Values = new LiveCharts.ChartValues<decimal> {1},
    },
    new LiveCharts.Wpf.PieSeries
    {
        Values = new LiveCharts.ChartValues<decimal> {3},
    }
};

foreach (LiveCharts.Wpf.PieSeries ps in psc)
{
    myPieChart.Series.Add(ps);
}

If anybody is interested, I discovered that doing

LiveCharts.SeriesCollection psc = new LiveCharts.SeriesCollection
{
    new LiveCharts.Wpf.PieSeries
    {
        Values = new LiveCharts.ChartValues<decimal> {1,1},
    },
    new LiveCharts.Wpf.PieSeries
    {
        Values = new LiveCharts.ChartValues<decimal> {3,7},
    }
};

foreach (LiveCharts.Wpf.PieSeries ps in psc)
{
    myPieChart.Series.Add(ps);
}

creates 2 concentric pie charts, one with values (1,3) and the other with values (1,7).

Upvotes: 3

Related Questions