Formatting data labels

I’m trying to format data labels with custom text string and font style. Here is a small example:


Workbook wb = new Workbook(“src.xlsx”);
Worksheet ws = wb.Worksheets[0];
Chart c = ws.Charts[0];
foreach (Series s in c.NSeries)
{
foreach (ChartPoint p in s.Points)
{
p.DataLabels.IsAutoText = false;
p.DataLabels.Text = “Test”;
p.DataLabels.Font.Color = Color.Blue;
p.DataLabels.Font.Size = 30;
}
}
wb.Save(“output.xlsx”);

The result of this code is that the data labels do not change at all. Am I calling it correctly?

Note: in my real application the style does vary by point, so I can’t just style the entire series.

Hi,


Thanks for providing us sample code.

After an initial test, I can notice the issue as you have mentioned by using your sample code. Data labels are not set (in the chart) with custom text in the output file.

I have logged a ticket with an id: CELLSNET-41079 for your issue. We will look into your issue to figure it out soon.

Thank you.

It looks like axis titles also do not respect font formatting,

Hi,


I have tried a few lines of code to set font attributes for Category Axis tick labels, it works fine, here is the sample code:

Sample code:

Workbook wb = new Workbook(“e:\test2\src.xlsx”);
Worksheet ws = wb.Worksheets[0];
Chart c = ws.Charts[0];
foreach (Series s in c.NSeries)
{

foreach (ChartPoint p in s.Points)
{
DataLabels d = p.DataLabels;
d.IsAutoText = false;
d.Text = “Test”;
d.Font.Color = Color.Blue;
d.Font.Size = 30;
}
}

c.CategoryAxis.TickLabels.Font.IsBold = true;
c.CategoryAxis.TickLabels.Font.Name = “Arial”;
c.CategoryAxis.TickLabels.Font.Size = 11;

wb.Save(“e:\test2\output.xlsx”);

Also, please download and try this fix: Aspose.Cells for .NET (Latest Version) , it works fine regarding the code in bold, but your original issue remains in it. We will fix your original issue soon.

If you have issue with Axis titles with the new fix, please provide us sample code and template file here, we will check it soon.

Thank you.

Not tick labels, axis titles:


c.ValueAxis.Title.Text = “Test”;
c.ValueAxis.Title.Font.Size = 44;

This code sets the title text but the font size does not work.

Hi,


I think it works fine using the latest fix: v7.3.1.5 as I tested using the code below. The font size of the axis title is also set to 44. Please try it and let us know the result.

Sample code:
Workbook wb = new Workbook(“e:\test2\src.xlsx”);
Worksheet ws = wb.Worksheets[0];
Chart c = ws.Charts[0];
foreach (Series s in c.NSeries)
{

foreach (ChartPoint p in s.Points)
{
DataLabels d = p.DataLabels;
d.IsAutoText = false;
d.Text = “Test”;
d.Font.Color = Color.Blue;
d.Font.Size = 30;
}
}

c.ValueAxis.Title.Text = “Test”;
c.ValueAxis.Title.Font.Size = 44;


wb.Save(“e:\test2\output.xlsx”);


Thank you.

You’re correct, that does work.


Thanks for your quick help.
Shaun

Hi,

Thanks for using Aspose.Cells.

I am afraid, your issue logged as CELLSNET-41079 is not fixed yet.

Please spare us few more working days to fix this issue.

Once, the issue is fixed or we have some other update for you, we will let you know asap.

Any progress on this issue?

Hi,

Thanks for using Aspose.Cells.

I am afraid, your issue is still unresolved. I have logged your comments against the issue id: CELLSNET-41079

Hopefully, your issue will be fixed soon.

Hi,

Thanks for using Aspose.Cells for .NET.

Please download and try the new fix: Aspose.Cells for .NET v7.3.3.3 and let us know your feedback.

Replace the test code “foreach (ChartPoint p
in s.Points)”
with “for (int i = 0; i < s.Points.Count; i++)”.



Aspose.Cells does not create Series.Points collection by default.

Hi,


And, here is the updated test code that I applied which works fine now with v7.3.3.3:

Sample code:

Workbook wb = new Workbook(“e:\test2\src.xlsx”);
Worksheet ws = wb.Worksheets[0];
Chart c = ws.Charts[0];
foreach (Series s in c.NSeries)
{
for (int i = 0; i < s.Points.Count; i++)
{
s.Points[i].DataLabels.IsAutoText = false;
s.Points[i].DataLabels.Text = “Test”;
s.Points[i].DataLabels.Font.Color = Color.Blue;
s.Points[i].DataLabels.Font.Size = 30;
}
}
wb.Save(“e:\test2\output.xlsx”);

The issues you have found earlier (filed as CELLSNET-41079) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.