如何使用LiveCharts创建饼图 [英] How to create a Pie Chart with LiveCharts

查看:746
本文介绍了如何使用LiveCharts创建饼图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用LiveCharts创建(测试)饼图的帮助.我正在使用此xaml代码

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

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

,然后在后面的代码中

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.

推荐答案

好的,我能够通过此操作完成工作

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);
}

创建2个同心圆饼图,一个同心圆饼图(1,3),另一个同心圆饼图(1,7).

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

这篇关于如何使用LiveCharts创建饼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆