How to create a Pie Chart with LiveCharts

匿名 (未验证) 提交于 2019-12-03 01:42:02

问题:

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.

回答1:

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).



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!