简体   繁体   中英

WPF Pie Chart how to add space between slices?

I am using Telerik (RadPieChart) with WPF. How can I add space between the slices ?

This is what I currently have: 在此处输入图片说明

And this is how I want my Pie chart to look like with the spaces between the slices: 在此处输入图片说明

Here is my source code:

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

Use the OffsetFromCenter property in PieDataPoint . Something like OffsetFromCenter = 0.015 should be similar to the above image.

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

饼形图

Increasing OffsetFromCenter to say 0.1 will render thicker lines:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM