Free Support Forum - aspose.com

Chart Label changes Position when Printed

Dear Aspose Support Team

The attached file PrintLabelPosition.xlsx has been created with Aspose.Cells (V 20.9.7). When the file is opened in Excel, the label ‘-8 %’ of the bar chart is correctly shown on the right hand side of the chart axis (see also Screenshot.PNG). However, when the file is printed directly from Aspose.Cells (e.g. to Microsoft XPS Document Writer), the label is printed on the left hand side (see Print.oxps). We would expect the label to be printed at the same position as it is shown in Excel.

PrintLabelPosition.zip (305.0 KB)

@awepler,

Please notice, I am able to reproduce the issue as you mentioned by using the following sample code with your template file. I found chart label’s position is changed when printed as you pointed out via the screenshot:
e.g.
Sample code:

Workbook workbook = new Workbook("f:/files/PrintLabelPosition.xlsx");
com.aspose.cells.ImageOrPrintOptions printOptions = new com.aspose.cells.ImageOrPrintOptions();
com.aspose.cells.WorkbookRender wr = new com.aspose.cells.WorkbookRender(workbook, printOptions);

wr.toPrinter("Microsoft XPS Document Writer");

I have logged a ticket with an id “CELLSJAVA-43313” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

Are there already any plans by when this will be fixed? Can we expect it in the next release? We have a big reporting beginning of November; it would be great if this works by then. Thank you for a short reply.

@awepler,
Please spare us little more time to analyze your issue. We will write back here soon to share our feedback.

@awepler,

This is to inform you that we have fixed your issue now. We will soon provide (within 3-5 days or so) you the fixed version after performing QA and incorporating other enhancements and fixes.

Thank you for the information. Do you have an estimate by when you can provide the fixed version?

@awepler,

We will try to provide the fixed version in the next couple of days for your issue(s).

Please stay tuned.

@awepler,
Please try our latest version/fix: Aspose.Cells for Java v20.10.7:
aspose-cells-20.10.7-java.zip (7.2 MB)

Your issue should be fixed in it.

Let us know your feedback.

We have recreated the file (PrintLabelPosition2.xlsx) with our code and the new Aspose.Cells for Java v20.10.7.
Printing (Print2.oxps) is now working fine, i.e. the label ‘-8 %’ is now correctly printed on the right hand side of the chart axis.
However, when opening the new file in Excel, it is not correctly displayed anymore, i.e. the label is shown on the left hand side of the chart axis.
We expect the label to be shown on the right hand side of the axis, both on the print-outs as well as in Excel, as we are deliberately moving the label over there in our code.

PrintLabelPosition2.zip (300.9 KB)

@awepler,

You are right as I tested with the latest fix. In “Chart 2”, the label ‘-8 %’ should be shown on the left hand side of the axis. I have reopened the issue again. We will look into it soon.

Sorry for any inconvenience caused!

Please note: we would like to have all the numeric labels printed on the right hand side of the axis (especially also those for negative bars). Basically, we are using LabelPositionType.OUTSIDE_END; however, this would show the labels for negative bars on the left hand side (which we do not want). Hence we are moving the labels for negative bars to the right hand side of the axis using below code. We expect the labels to be shown / printed on the right hand side of the axis both in MS Excel as well as in printouts (or PDFs).

		// move labels for negative bars to the right of the vertical axis
		series.getDataLabels().setPosition(LabelPositionType.INSIDE_BASE);
		chart.calculate();
		// determine leftmost position to the right of the axis (i.e. for positive values)
		int minPositiveX = Integer.MAX_VALUE;
		ChartPointCollection points = series.getPoints();
		for (int i = 0; i < points.getCount(); i++) {
			ChartPoint point = points.get(i);
			int currentX = point.getDataLabels().getX();
			if (currentX < minPositiveX && !isNegative(point.getYValue()))
				minPositiveX = currentX;
			point.getDataLabels().setPosition(LabelPositionType.OUTSIDE_END);
		}
		// move labels too far to the left to minPositiveX
		chart.calculate();
		for (int i = 0; i < points.getCount(); i++) {
			DataLabels label = points.get(i).getDataLabels();
			if (label.getX() < minPositiveX) {
				label.setX(minPositiveX);
			}
		}

Could you share runnable sample code and sample files (input Excel file (if any), output Excel file and expected Excel file to evaluate your issue precisely. We will check it soon. Also, give PDF output by Aspose.Cells.

Please find attached a runnable sample (PrintLabelPosition.java). We ran it twice:
(i) with Aspose.Cells for Java v20.9.7
(ii) with Aspose.Cells for Java v20.10.7

There are no input Excel files, the output is created from scratch. Output Excel, PDF and print files are attached; naming is hopefully self-explanatory. For PDF and print outputs it seems to make a difference whether the workbook is reloaded from the file after saving or not. Hence we provided ‘before’ and ‘after’ versions.

Files that are OK (i.e. show the negative label on the right hand side):
SampleOutput_V-20-9-7.xlsx
SampleOutput_before_V-20-9-7.pdf
Print_before_V-20-9-7.oxps
SampleOutput_before_V-20-10-7.pdf
SampleOutput_after_V-20-10-7.pdf
Print_before_V-20-10-7.oxps
Print_after_V-20-10-7.oxps

Files that are NOT OK (i.e. show the negative label on the left hand side):
SampleOutput_after_V-20-9-7.pdf
Print_after_V-20-9-7.oxps
SampleOutput_V-20-10-7.xlsx

RunnableSample.zip (206.9 KB)

@awepler,
We are analyzing this data and will share our feedback soon.

@awepler,

We did test your scenario/case using your sample code and confirmed your issue(s) as you described. We found the issue is there in the output PDFs and output printouts .oxps files. We will continue to investigate your issue and try to figure it out.

Once we have any new information available, we will update you.

The issues you have found earlier (filed as CELLSJAVA-43313) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi

Thank you for providing the latest update of Aspose.
The horizontal placement of the negative label with respect to the axis (to the left vs. right of the axis) seems to be working OK now.
However, the vertical alignment (y-coordinate) of the negative label (with respect to the category label) seems to be a bit off. This is clearly visible in the .xlsx file. It can also be seen (to a smaller extent) in the .pdf and .oxps files.
Maybe this is related to (Re)Setting y-coordinate changes position of category axis title

Output_V-20-11.zip (102.8 KB)

@awepler,
I have tried to observe the difference between the ‘before’ and ‘after’ PDF/OXPS files but could not observe the problem. Please share a comparison image showing the issue for our reference. We will reproduce the problem here and share our feedback accordingly.
image.jpg (180.7 KB)

It is not a ‘before’ vs. ‘after’ issue. Also, it is not a new issue, it was already present in V20.9.7. Sorry, for not being clear on that.
We would expect the negative label to be vertically aligned with the category label. That is, both the category label ‘E’ and the negative label ‘-8 %’ should sit on the (ideally straight) green line in the screenshot. However, the ‘-8 %’ is shown too far to the top. The screenshot has been taken from Excel, where the issue is visible most clearly. In the .pdf and .oxps files the alignment is much better and you have to zoom in to really see the difference.

Screenshot_Excel.PNG (10.8 KB)

@awepler,
I have tried the scenario again and afraid to share that issue is not observed as mentioned by you. You may please ensure that you are testing the scenario with the latest version 20.11. Here is the comparison of your image and pdf output generated with the latest version.
image.jpg (248.1 KB)