Hi Team:
I upgraded Dll from 21.3 to 21.5 and found that I couldn’t modify the data label position of the doughtnut Chart normally.
Sample code:
Workbook workbook = new Workbook(“e:\doughtnut.xlsx”);
Worksheet worksheet = workbook.Worksheets[0];
int chartIndex = worksheet.Charts.Add(ChartType.Pie, 0, 5, 20, 15);
Chart chart = worksheet.Charts[chartIndex];
chart.Title.IsDeleted = true;
chart.PlotArea.Area.FillFormat.FillType = FillType.None;
chart.PlotArea.Border.FormattingType = ChartLineFormattingType.None;
chart.ChartArea.Border.FormattingType = ChartLineFormattingType.None;
chart.ChartArea.Area.FillFormat.FillType = FillType.None;
chart.ShowLegend = false;
var chartRange = $"{CellsHelper.CellIndexToName(1, 1)}:{CellsHelper.CellIndexToName(4, 1)}";
chart.NSeries.Add(chartRange, true);
chart.NSeries.CategoryData = $"{CellsHelper.CellIndexToName(1, 0)}:{CellsHelper.CellIndexToName(4, 0)}";
for (int i = 1; i <= chart.NSeries.Count; i++)
{
var series = chart.NSeries[i - 1];
series.Name = $"={CellsHelper.CellIndexToName(0, i)}";
series.DataLabels.ShowCategoryName = true;
series.DataLabels.ShowValue = true;
series.DataLabels.SeparatorType = DataLabelsSeparatorType.Comma;
series.DataLabels.NumberFormatLinked = true;
series.DataLabels.Position = LabelPositionType.OutsideEnd;
}
chart.Calculate();
List<(int x, int y)> points = new List<(int x, int y)>();
foreach (var series in chart.NSeries)
{
foreach (ChartPoint item in series.Points)
{
points.Add((item.DataLabels.X, item.DataLabels.Y));
}
}
chart.Type = ChartType.Doughnut;
chart.Calculate();
for (int i = 1; i <= chart.NSeries.Count; i++)
{
var series = chart.NSeries[i - 1];
series.HasLeaderLines = false;
var pointLength = series.Points.Count;
for (int j = 0; j < pointLength; j++)
{
var pos = points[j];
var point = series.Points[j];
point.DataLabels.X = pos.x;
point.DataLabels.Y = pos.y;
}
}
chart.Calculate();
workbook.Save("e:\\output.xlsx");
doughtnut.zip (77.7 KB)