Hi,
I’m not sure why but using nested foreach to set custom datalabels doesn’t seem to work, but using nested for loops does, is this normal?
Here is the test code, unless I’m missing something, I’d expect both images to be the same, for now I’ll just use the “for method” but since I lost some time on this I figured I’d report it just in case it’s an issue that might need to be fixed
chartFor.png is my expected result, while chartForeach.png isn’t
Workbook workbook = new Workbook();
int sheetIndex = workbook.Worksheets.Add();
Worksheet worksheet = workbook.Worksheets[sheetIndex];
//Values to generate chart with (to ensure a minimum column size)
worksheet.Cells[0, 0].PutValue(2000);
worksheet.Cells[1, 0].PutValue(600);
worksheet.Cells[0, 1].PutValue(3000);
worksheet.Cells[1, 1].PutValue(600);
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:B3”, true);
foreach (Aspose.Cells.Charts.Series series in chart.NSeries)
{
foreach (Aspose.Cells.Charts.ChartPoint point in series.Points)
{
point.DataLabels.Text = “Test”;
}
}
chart.ToImage(“chartForeach.png”); //No labels are shown?
for (int seriesIdx = 0; seriesIdx < chart.NSeries.Count; seriesIdx++)
{
for (int pointIdx = 0; pointIdx < chart.NSeries[seriesIdx].Points.Count; pointIdx++)
{
chart.NSeries[seriesIdx].Points[pointIdx].DataLabels.Text = “Test”;
}
}
chart.ToImage(“chartFor.png”); //While here they are, I’d expect both methods to yield the same results
Hi,
- CELLSNET-44896 - Setting DataLabels.Text on data points using foreach does not work