chart.toImage doesn't include data labels

This worked in aspose 7.4.0.3 (yes, really), and no longer works as of 19.8.0.

We started with code to create an Excel document and a chart, and then created an image based on that chart. The chart contains labels. As of 7.4.0.3, this worked. (See images.)

Excel:

image.png (6.3 KB)

PNG:

image.png (17.6 KB)

Now the same using new(er) code (19.8.0):

Excel:

image.png (6.7 KB)

PNG:

image.png (17.4 KB)

Is there a way to make this work using newest aspose? (Note: all code is identical between these two examples; only difference is the aspose jar.)

Our code (which expects the license file to be at File licenseFile = new File(“aspose-licenses/Aspose-Cells-License-New.xml”);):


package com.athenium;

import com.aspose.cells.*;

import java.io.*;

public class AsposeTestHarness {
	public static final String CHART_SHEET_NAME = "chart";
	public static final String DATA_SHEET_NAME = "data";
	public static void main(String[] args) {
		initNewLicense();
		// init workbook
		Workbook wb = new Workbook();
		WorksheetCollection sheets = wb.getWorksheets();
		sheets.clear();

		// init sheets
		Worksheet chartSheet = sheets.add(AsposeTestHarness.CHART_SHEET_NAME);
		ChartCollection charts = chartSheet.getCharts();
		Worksheet dataSheet = wb.getWorksheets().add(DATA_SHEET_NAME);
		Cells dataSheetCells = dataSheet.getCells();

		// init chart
		Chart chart = charts.get(charts.add(ChartType.BAR_100_PERCENT_STACKED, 0, 0, 20, 10));
		SeriesCollection nSeries = chart.getNSeries();

		// write data
		dataSheetCells.get(0,1).setValue("Incorrect %");
		dataSheetCells.get(0,2).setValue("Correct %");
		dataSheetCells.get(1,0).setValue("Question 1");
		dataSheetCells.get(1,1).setValue(0.12);
		dataSheetCells.get(1,2).setValue(0.88);
		dataSheetCells.get(2,0).setValue("Question 2");
		dataSheetCells.get(2,1).setValue(0.21);
		dataSheetCells.get(2,2).setValue(0.79);
		dataSheetCells.createRange(1,0,2,1).setName("Categories");
		dataSheetCells.createRange(1,1,2,1).setName("IncorrectPct");
		dataSheetCells.createRange(1,2,2,1).setName("CorrectPct");
		Series incorrectSeries = nSeries.get(nSeries.add("IncorrectPct", true));
		incorrectSeries.setName("Incorrect %");
		Series correctSeries = nSeries.get(nSeries.add("CorrectPct", true));
		correctSeries.setName("Correct %");
		nSeries.setCategoryData("Categories");

		// format labels
		DataLabels incorrectLabels = incorrectSeries.getDataLabels();
		DataLabels correctLabels = correctSeries.getDataLabels();

		incorrectLabels.setShowLegendKey(false);
		correctLabels.setShowLegendKey(false);

		incorrectLabels.setAutoText(true);
		correctLabels.setAutoText(true);

		incorrectSeries.setHasLeaderLines(true);
		correctSeries.setHasLeaderLines(true);

		incorrectLabels.setShowSeriesName(false);
		correctLabels.setShowSeriesName(false);

		incorrectLabels.setShowCategoryName(false);
		correctLabels.setShowCategoryName(false);

		incorrectLabels.setShowValue(true);
		correctLabels.setShowValue(true);

		incorrectLabels.setShowPercentage(true);
		correctLabels.setShowPercentage(true);

		incorrectLabels.setShowBubbleSize(true);
		correctLabels.setShowBubbleSize(true);

		incorrectLabels.setAutoScaleFont(false);

		correctLabels.setNumberFormat("0.00");

		incorrectLabels.setBackgroundMode(BackgroundMode.OPAQUE);
		correctLabels.setBackgroundMode(BackgroundMode.TRANSPARENT);

		// write excel file
		writeFile(wb);

		// write image file
		ImageOrPrintOptions ops = new ImageOrPrintOptions();
		ops.setChartImageType(ImageFormat.getImageFormatFromSuffixName("png"));

		try {
			FileOutputStream fos = new FileOutputStream(new File("out/img.png"));
			chart.toImage(fos, ops);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private static void initNewLicense() {
		try {
			File licenseFile = new File("aspose-licenses/Aspose-Cells-License-New.xml");
			InputStream licenseFileStream = new FileInputStream(licenseFile);
			License asposeCellsLicense = new License();
			asposeCellsLicense.setLicense(licenseFileStream);
			if (License.isLicenseSet()) {
				System.out.println("License OK");
			} else {
				System.out.println("License NOT set!");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static void writeFile(Workbook wb) {
		try {
			wb.save("out/workbook.xls", SaveFormat.EXCEL_97_TO_2003);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

@jstrachman,
Please share your sample file with us for our testing. We will reproduce the problem and provide our feedback after analysis.

Hi! Thanks for responding. There is no “sample file.” The code I supplied generates the file from scratch. Do you need the results files (output)? I can send those to you, although the code I gave you will generate them. Hope that helps! Thanks!

@jstrachman,

After an initial test, I am able to reproduce the issue as you mentioned by using your sample code. I found I found Chart.toImage does not include data labels in the output image although the chart in the output Excel file is having data labels fine. I have logged a ticket with an id “CELLSJAVA-43133” for your issue. We will look into it soon.

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

Awesome, thank you very much!

@jstrachman,

You are welcome.

@Amjad_Sahi Hi Amjad! I just wanted to follow up on this. Has there been any movement on fixing this bug?

Thanks!

@jstrachman,

Your issue is still in progress as we are working over it. Hopefully it will be resolved soon.
We will also check if we can provide you an ETA (if it will take more time).

Once we have any new information available, we will share it with you.

@jstrachman,
We have figured out the issue, we will try to fix it this week. Once we have any further update on it, we will let you know here.

Awesome, thanks so much.

@jstrachman,

Please try our latest version/fix: Aspose.Cells for Java v20.3.3 (attached)

Your issue should be fixed in it.

Let us know your feedback.
aspose-cells-20.3.3-java.zip (7.0 MB)

Awesome, thank you! I will submit this to my dev team and get this checked out asap. Much appreciated.

@jstrachman,

You are welcome.

The issues you have found earlier (filed as CELLSJAVA-43133) have been fixed in Aspose.Cells for Java v20.4. This message was posted using Bugs notification tool by ahsaniqbalsidiqui