首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在LiveCharts中创建饼图切片

在LiveCharts中创建饼图切片
EN

Stack Overflow用户
提问于 2017-01-10 06:53:15
回答 0查看 7.1K关注 0票数 0

我正在使用LiveCharts创建一个饼图。我有一个要在饼图中表示的替身列表。问题是列表的值可以并且将会更改,因此我希望能够相应地更改图表。

以下是来自LiveCharts网站的一些示例代码:

代码语言:javascript
复制
using System;
using System.Windows.Forms;
using LiveCharts;
using LiveCharts.Wpf;

namespace Winforms.PieChart
{
public partial class PieChartExample : Form
{
    public PieChartExample()
    {
        InitializeComponent();

        Func<ChartPoint, string> labelPoint = chartPoint =>
            string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);

        pieChart1.Series = new SeriesCollection
        {
            new PieSeries
            {
                Title = "Maria",
                Values = new ChartValues<double> {3},
                PushOut = 15,
                DataLabels = true,
                LabelPoint = labelPoint
            },
            new PieSeries
            {
                Title = "Charles",
                Values = new ChartValues<double> {4},
                DataLabels = true,
                LabelPoint = labelPoint
            },
            new PieSeries
            {
                Title = "Frida",
                Values = new ChartValues<double> {6},
                DataLabels = true,
                LabelPoint = labelPoint
            },
            new PieSeries
            {
                Title = "Frederic",
                Values = new ChartValues<double> {2},
                DataLabels = true,
                LabelPoint = labelPoint
            }
        };

        pieChart1.LegendLocation = LegendLocation.Bottom;
    }
}

}

本质上,我想做同样的事情,但不是迭代列表,而是为饼图创建适当数量的切片。LiveCharts提供了PieSlices,但PieChart Control只接受SeriesCollection,这就是当我将pieChartData赋给图表时代码崩溃的原因。以下是我填充PieChart的尝试:

代码语言:javascript
复制
        LiveCharts.Wpf.PieChart pieChartData = new LiveCharts.Wpf.PieChart();

        foreach (var n in areavalues)
        {
            pieChartData.AddToView(new PieSlice
            {
                PieceValue = n
            });
        }

        areaChart.Series.Add(new PieSeries(pieChartData)); //<-- CRASH

我很难找到LiveCharts的其他示例代码,有人知道如何做到这一点吗?

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41558338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档