我在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;
}
答案 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;
}
将OffsetFromCenter
说成0.1
会增加粗线: