I use LiveCharts2 (beta.950) library to work with charts. I tried to create a PieChart with some values and labels outside it and I got this:
The PieChart is inside a border and as you can see - the labels are cut off. There are no margins or something like this in xaml code, only the PieChart control:
<lvc:PieChart Series="{Binding CartesianPieChartSeries}"></lvc:PieChart>
I fill up the chart like this (it is simplified version):
SKColor[] colors = new SKColor[] { SKColors.AntiqueWhite, SKColors.Crimson, SKColors.Maroon, SKColors.Aqua, SKColors.Silver };
var vals = new PieSeries<double>[5];
for (int i = 0; i < 5; ++i)
{
var color = colors[i];
vals[i] = new PieSeries<double>
{
Values = new double[] { i + 1 },
InnerRadius = 120,
Fill = new SolidColorPaint(color),
DataLabelsPaint = new SolidColorPaint(SKColors.Black),
DataLabelsFormatter = point =>
{
var sv = point.StackedValue;
var a = $"{(int)sv.Share:P0}";
return a;
},
IsHoverable = false,
AnimationsSpeed = null,
DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.Outer
};
}
CartesianPieChartSeries = vals;
So there are two questions. Why do the labels cut off and why are the percentage labels all zero?
Because you are casting to
int
. Try this:As for the labels issue, I guess you could change the
DataLabelsPosition
property to another value or increase the margins around the chart.Or use a negative
DataLabelsPadding
: