I’ve searched for a while but can’t seem to find any solution, I want to confirm if it’s possible or not
Is there a way to avoid the labels from overlapping when setting ShowValue = true?
I’d like to be able to set a minimal height for each series that would allow for the text to always fit inside the column subsection dedicated to each value.
If it can help, I don’t really mind if the spacing on the Y axis ends up being uneven as a result since I usually hide the axis.
Here’s a code snippet that shows my issue, I’ve attached the resulting chart image as well
Workbook workbook = new Workbook();
int sheetIndex = workbook.Worksheets.Add();
Worksheet worksheet = workbook.Worksheets[sheetIndex];
worksheet.Cells[“A1”].PutValue(2000);
worksheet.Cells[“A2”].PutValue(50);
worksheet.Cells[“B1”].PutValue(50);
worksheet.Cells[“B2”].PutValue(25);
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.ColumnStacked, 10, 0, 20, 10);
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
chart.NSeries.Add(“A1:B2”, true);
foreach (Aspose.Cells.Charts.Series serie in chart.NSeries)
{
serie.DataLabels.ShowValue = true;
}
chart.ToImage(“DataLabelOverlap.png”);
Hi,
Hi
There doesn’t seem to be any trivial way to do what I want in Excel
So far the only idea I have would be to use a different set of data series for the labels and for the data used in the graph.
Essentially the labels would use the real data, and I’d use a 2nd set of data to draw the graph columns themselves. I’d apply a minimum on this 2nd set of data so that each section is big enough to fit the text properly.
It’s kind of a big hack but since nothing else seems to be available out of the box…
For now it should be good enough
Thank you for your feedback
Hi,
Worksheet ws = wb.Worksheets[0];
Chart ch = ws.Charts[0];
ch.Calculate();
Series srs = ch.NSeries[0];
for(int i=0; i<srs.Points.Count; i++)
{
ChartPoint o = srs.Points[i];
o.DataLabels.X += 150;
}
wb.Save(“output.xlsx”);