Chart.ToImage() and DataLabels positioning

Hello,

I found an issue with the Chart.ToImage() method. If you try the code below and check the output files, you will notice that whilst the XLS file correctly positions the labels (so they won’t overlap), the corresponding image does not. This is important to me because I have some pie charts with many slices and some of them are overlapping their labels.

Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];

sheet.Cells[0, 0].PutValue(“A”);
sheet.Cells[0, 1].PutValue(“BB”);
sheet.Cells[0, 2].PutValue(“CCC”);
sheet.Cells[0, 3].PutValue(“DDDD”);
sheet.Cells[0, 4].PutValue(“EEEEE”);
sheet.Cells[0, 5].PutValue(“FFFFFF”);
sheet.Cells[1, 0].PutValue(100);
sheet.Cells[1, 1].PutValue(50);
sheet.Cells[1, 2].PutValue(25);
sheet.Cells[1, 3].PutValue(12.5);
sheet.Cells[1, 4].PutValue(6.25);
sheet.Cells[1, 5].PutValue(3.175);

int chart_index = sheet.Charts.Add(Aspose.Cells.ChartType.Pie, 5, 5, 5, 5);
Chart chart = sheet.Charts[chart_index];

chart.FirstSliceAngle = 90;
chart.SizeWithWindow = true;
chart.IsLegendShown = false;
chart.ChartArea.Background = BackgroundMode.Transparent;
chart.ChartArea.Border.IsVisible = false;

chart.Title.Text = “Great test”;
chart.Title.TextFont.IsBold = false;
chart.Title.TextFont.Size = 24;
chart.Title.Border.IsVisible = false;
chart.Title.Background = BackgroundMode.Transparent;

chart.ChartObject.Height = (int)(306 * 1.6);
chart.ChartObject.Width = (int)(380 * 1.6);

chart.PlotArea.Height = (int)Math.Round(3270 / 1.5);
chart.PlotArea.Width = (int)Math.Round(3574 / 1.5);
chart.PlotArea.X = 280 + (int)((3270 - (int)Math.Round(3270 / 1.5)) / 2);
chart.PlotArea.Y = 400 + (int)((3574 - (int)Math.Round(3574 / 1.5)) / 2);

chart.NSeries.Add(“A2:F2”, false);
chart.NSeries.CategoryData = “A1:F1”;
chart.NSeries.IsColorVaried = true;

chart.NSeries[0].DataLabels.Postion = LabelPositionType.BestFit;
chart.NSeries[0].DataLabels.IsValueShown = false;
chart.NSeries[0].DataLabels.IsCategoryNameShown = true;
chart.NSeries[0].DataLabels.IsPercentageShown = true;
chart.NSeries[0].DataLabels.Separator = DataLablesSeparatorType.NewLine;

sheet.Charts[0].ToImage(“c:\test.bmp”);
book.Save(“c:\test.xls”);


Is this an easy issue to fix?

Thanks for your help,

Cruz

Hi Cruz,

Thanks for providing us the source code.

We found the issue and will fix it soon.

Thank you.

Hi Amjad,

I was wondering if you have any news on this issue. Do have any timings?

Thanks again,
Cruz

Hi Cruz,

Thanks for following up.

We will get back to you soon.

Thanks for being patient!

Hello again,

Really sorry to bother you again with this, but I really need an update on this issue. My project is awaiting production because of this.

Do you have any timings for me?
Thanks for all the support,
Cruz

Hi,

We provide a fix for the issue at the end of next week. The issue is more complex as the leader lines are depend on the pie slices and at the same time the pie slices affect the leader lines.

Hi there,

Ok, I understand your point. I’ll wait till next week, then.

Thanks again for your patience,
Cruz

Hello again,

Sorry to bother you again, but I found another issue with the ToImage method.

Just run this code with the attached template file:

Workbook book = new Workbook();
book.Open(“c:\test.xls”);

book.Worksheets[0].Charts[0].ToImage(“c:\test.bmp”);

You will notice that the alignment of the ticklabels is not correct in the resulting image, as they should be aligned vertically on top (next to the axis) but they are being aligned on the vertical center.

Thanks in advance,
Cruz

Hi Cruz,

Thanks for the template file.

We did the conversion (chart2image) and yes, we noticed the issue (you have mentioned). We will figure it out soon.

Thank you.

Hello, again.

Can you give me some feedback on this issue? It’s been a month since your last reply.

Thanks in advance
Cruz

Hi Cruz,

Please try this fix.

We have supported leader line and fixed the bug of area' s color.

Hi, thanks for the fix.

I found an issue, though. Please regard the attached test files.

Simply open the xls file and use the ToImage method in the chart. The result is also attached.

I tested the leader lines both by creating a chart from scratch, which was fine, but when I tested with a chart built in excel, the result is as attached.

Thanks in advance,
Cruz

Hi,

Thanks for providing us the template excel file.

We will figure it out soon.

Thank you.

In the last fix, I only considered to fit your requirement and did not take notice of the chart if it was built in excel manually. Now, I think the previous fix has some serious bugs. In th current fix (attached), we have fixed the bug if the chart was built in MS Excel 2003 (2007 not supported yet) but it does not work fine in case if you are creating the chart from the scratch since there is still a bug in saving excel file. We will look into it soon.

Thank you.

Ok, thanks for the fix. I will test it and get back to you soon.

Cruz

Ok, I have done some tests on the fix but I’m having some problems with the leader lines.

Here is a sample code. Basically the output excel file represents exactly what I want of the leader lines, but the generated image is different from the output excel file.

Please try this code and check with the attached files

Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];

sheet.Cells[0, 0].PutValue(“veeeeeeery loooooooong name”);
sheet.Cells[0, 1].PutValue(“small name”);
sheet.Cells[0, 2].PutValue(“normal nnaammee”);
sheet.Cells[0, 3].PutValue(“another relatively long name”);
sheet.Cells[0, 4].PutValue(“naaaaaaaameeeeeeeee”);
sheet.Cells[0, 5].PutValue(“i also have a naaaaaameee”);
sheet.Cells[0, 6].PutValue(“my name is loooong”);
sheet.Cells[1, 0].PutValue(100);
sheet.Cells[1, 1].PutValue(50);
sheet.Cells[1, 2].PutValue(25);
sheet.Cells[1, 3].PutValue(12.5);
sheet.Cells[1, 4].PutValue(6.25);
sheet.Cells[1, 5].PutValue(3.175);
sheet.Cells[1, 6].PutValue(1.175);

int chart_index = sheet.Charts.Add(Aspose.Cells.ChartType.Pie, 5, 5, 5, 5);
Chart chart = sheet.Charts[chart_index];

chart.FirstSliceAngle = 90;
chart.SizeWithWindow = true;
chart.IsLegendShown = false;
chart.ChartArea.Background = BackgroundMode.Transparent;
chart.ChartArea.Border.IsVisible = false;

chart.Title.Text = “Great test”;
chart.Title.TextFont.IsBold = false;
chart.Title.TextFont.Size = 24;
chart.Title.Border.IsVisible = false;
chart.Title.Background = BackgroundMode.Transparent;

chart.ChartObject.Height = (int)(306 * 1.6);
chart.ChartObject.Width = (int)(380 * 1.6);

chart.PlotArea.Height = (int)Math.Round(3270 / 1.5);
chart.PlotArea.Width = (int)Math.Round(3574 / 1.5);
chart.PlotArea.X = 280 + (int)((3270 - (int)Math.Round(3270 / 1.5)) / 2);
chart.PlotArea.Y = 400 + (int)((3574 - (int)Math.Round(3574 / 1.5)) / 2);

chart.NSeries.Add(“A2:G2”, false);
chart.NSeries.CategoryData = “A1:G1”;
chart.NSeries.IsColorVaried = true;

chart.NSeries[0].DataLabels.Postion = LabelPositionType.BestFit;
chart.NSeries[0].DataLabels.IsValueShown = false;
chart.NSeries[0].DataLabels.IsCategoryNameShown = true;
chart.NSeries[0].DataLabels.IsPercentageShown = true;
chart.NSeries[0].DataLabels.Separator = DataLablesSeparatorType.NewLine;

book.Worksheets[0].Charts[0].ToImage(“c:\test.emf”, System.Drawing.Imaging.ImageFormat.Emf);

book.Save(“c:\test.xls”);

Am I’m missing something in this code?
Thanks once more for your support and sorry to bother you again,
Cruz

Hi Cruz,

Yes, we noticed the issue you have mentioned. We will look into it soon.

Thank you.

Hello again,

I was wondering if you have any updates or at least a timing for this issue, since this is the only issue that’s left for my project to complete.

Thanks again for your patience,
Cruz

Hi,

We are working on your issue. Hopefully, a fix would be provided as soon as we figure it out.

Thanks for being patient!

Hi,

Please try this fix.The chart image is similar to the display in MS Excel.

BTW, there is another issue in this fix. If you custom the position and size of plot area, MS Excel will custom the position and size of all objects(Title,Legend,DataLabels ...) in the chart, we do not change them now. So the plot area in MS Excel is less than your setting. We will look into this issue. It will take us a long time to support this issue.