WPF饼图如何在切片之间添加空间?

时间:2018-08-20 12:31:05

标签: c# wpf telerik

我在WPF中使用Telerik(RadPieChart)。如何在切片之间添加空间?

这是我目前拥有的: enter image description here

这就是我希望饼图在切片之间具有空格的样子: enter image description here

这是我的源代码:

private DoughnutSeries CreateDognutSerie(KeyValuePair<ChartSerie, List<ChartDataPoint>> chartSerie, int index, int count)
    {
        double spaceBetweenSperies = 0.0;
        if (count > 1 && index != count - 1)
        {
            spaceBetweenSperies = 0.007;
        }

        var doughnutSerie = new DoughnutSeries()
        {
            ShowLabels = true,
            //LabelConnectorsSettings = new ChartSeriesLabelConnectorsSettings()
            //{

            //},
            InnerRadiusFactor = index / (double)count,
            RadiusFactor      = ((index + 1) / (double)count) - spaceBetweenSperies,
            //LegendSettings = new DataPointLegendSettings()
            //{

            //},
            //SeriesAnimation = new PieChartAngleRangeAnimation()
            //{
            //    InitialStartAngle = -90,
            //    InitialSweepAngle = 180,
            //    Duration          = new TimeSpan(0, 0, 0, 0, 800),
            //}
        };
        foreach (ChartDataPoint serie in chartSerie.Value)
        {
            doughnutSerie.DataPoints.Add(new PieDataPoint()
            {
                Label = serie.XPoint.Label,
                Value = Math.Abs((double?)serie.Value ?? 0),
            });
        }

        return doughnutSerie;
    }

1 个答案:

答案 0 :(得分:3)

使用OffsetFromCenter中的PieDataPoint属性。 OffsetFromCenter = 0.015之类的图片应类似于上图。

public MainWindow()
{
    InitializeComponent();

    var data = new Dictionary<string, double>
    {
        { "January", 5 },
        { "February", 3 },
        { "March", 5 },
        { "April", 7 },
        { "May", 2 },
        { "June", 11 },
        { "July", 11 },
        { "August", 11 },
        { "September", 11 },
        { "October", 11 },
        { "November", 11 },
        { "December", 12 },
    };

    var series = CreateDougnutSeries(data);
    var pie = new RadPieChart { Palette = ChartPalettes.Fluent };
    pie.Series.Add(series);

    mainGrid.Children.Add(pie);

}

private DoughnutSeries CreateDougnutSeries(Dictionary<string, double> data)
{
    var doughnutSeries = new DoughnutSeries
    {
        ShowLabels = true,
        InnerRadiusFactor = 0,
        RadiusFactor = 1
    };

    foreach (var point in data)
    {
        doughnutSeries.DataPoints.Add(new PieDataPoint()
        {
            Label = point.Key,
            Value = point.Value,
            OffsetFromCenter = 0.015
        });
    }

    return doughnutSeries;
}

PieChart

OffsetFromCenter说成0.1会增加粗线:

enter image description here