gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 21:32:55 24 4
gpt4 key购买 nike

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

最佳答案

PieDataPoint 中使用 OffsetFromCenter 属性。 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

关于c# - WPF饼图如何在切片之间添加空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51930819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com