为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C#
浮云间 2021-12-05 16:21:09
我在 WPF 中使用 Telerik(RadPieChart)。如何在切片之间添加空间?这是我目前拥有的:这就是我希望饼图在切片之间有空格的样子:这是我的源代码: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 回答

?
一只萌萌小番薯

TA贡献1795条经验 获得超7个赞

使用中的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;

}

//img1.sycdn.imooc.com//61ac76b700013ec704120366.jpg

增加OffsetFromCenter0.1会渲染更粗的线条:


//img1.sycdn.imooc.com//61ac76c1000198b503690346.jpg

查看完整回答
反对 回复 2021-12-05
  • 1 回答
  • 0 关注
  • 185 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信