Chart toImage fails to maintain the color for Single series Line charts

Hi,

I am trying to embed an an excel OLE (that has both data
sheet and
chart sheet) into a presentation slide. The excel chart is a Line chart with single series of data. I also wanted to put the Line chart snapshot image as foreground picture in the slide using Chart.toImage();

I have also applied various colors for each of the point using ChartPoint.getBorder().setColor(). Note: There is only one line in the chart.

I
was able to do so, but the snapshot image that got created doesn’t has the colors same as the chart. The snapshot image line color has a unique color for all the points. If I double click, I can see the chart with colors applied properly.

I have also attached the generated presentation along with this…,

I am using aspose-cells-2.5.4-java.zip and aspose-slides-2.5.0-java.zip with our setup…

Can you suggest what could be wrong in this?

Regards
Sundhar
Aspose OEM Licence Holder

Hi Sundhar,

I have observed the presentation shared by you. It will be really nice if you provide the code snippet that you are using on your end. Please also the generated presentation where you have added the chart image. Please also share which version of Aspose.Slides for Java and Aspose.Cells for Java you are using. You may please also observe that Chart.toImage() method belongs to Aspose.Cells and if the the image is saved as file and has similar issue as that have been observed by you in your presentation then it belongs to Aspose.Cells for Java. However, if the generated chart image is rendered fine as file but look problematic in presentation then we will investigate it on our end. Please provide the necessary data for investigation on our end and also perform the requested mechanism as shared by me.

Thanks and Regards,

For my scenario, I wanted to embed the image snapshot in PPT, for which the image file need not be saved in the filesystem… So, i filed this post is Aspose slides…, suggest if this has to be moved to Aspose cells or not.

I tried as you said, by saving the image as a file., but I still face the same problem…, So, looks like the problem is with aspose cells API’s…

I am using aspose-cells-2.5.4-java.zip and aspose-slides-2.5.0-java.zip with our setup…

I have attached the code snippet and the generated ppt along with this and pasted the code below too…

Presentation presentation = new Presentation();
Slide slide = presentation.getSlideByPosition(1);

Workbook workbook = new Workbook();
Worksheets worksheets = workbook.getWorksheets();
worksheets.removeSheet(0);
Worksheet dataSheet = worksheets.addSheet(SheetType.WORKSHEET, “Data”);
Worksheet chartSheet = worksheets.addSheet(SheetType.CHART, “Chart”);
worksheets.setActiveSheet(chartSheet);
Chart chart = chartSheet.getCharts().addChart(ChartType.LINE, 0, 0, 0, 0, 50, 50);

Cells cells = dataSheet.getCells();

cells.getCell(“A1”).setValue("");
cells.getCell(“B1”).setValue(“Total”);
cells.getCell(“A2”).setValue(“Russia”);
cells.getCell(“B2”).setValue(100);
cells.getCell(“A3”).setValue(“England”);
cells.getCell(“B3”).setValue(140);
cells.getCell(“A4”).setValue(“Alaska”);
cells.getCell(“B4”).setValue(195);
cells.getCell(“A5”).setValue(“France”);
cells.getCell(“B5”).setValue(175);
cells.getCell(“A6”).setValue(“Oklahoma”);
cells.getCell(“B6”).setValue(95);
cells.getCell(“A7”).setValue(“Sydney”);
cells.getCell(“B7”).setValue(125);
cells.getCell(“A8”).setValue(“Columbia”);
cells.getCell(“B8”).setValue(82);
cells.getCell(“A9”).setValue(“Berlin”);
cells.getCell(“B9”).setValue(167);
cells.getCell(“A10”).setValue(“Thailand”);
cells.getCell(“B10”).setValue(183);

int index = chart.getNSeries()
.add("=Data!A1:B10", true, true, true);
chart.getNSeries().get(index).setName("=Data!" + “B1”);

dataSheet.autoFitColumns();

chart.setSizeWithWindow(false);
chart.setLegendShown(false);

ChartPoints chartPoints = chart.getNSeries().get(0)
.getChartPoints();
chartPoints.getChartPoint(0).getBorder().setColor(Color.BLACK);
chartPoints.getChartPoint(1).getBorder().setColor(Color.BLUE);
chartPoints.getChartPoint(2).getBorder().setColor(Color.CYAN);
chartPoints.getChartPoint(3).getBorder().setColor(Color.LIME);
chartPoints.getChartPoint(4).getBorder().setColor(Color.MAGENTA);
chartPoints.getChartPoint(5).getBorder().setColor(Color.MAROON);
chartPoints.getChartPoint(6).getBorder().setColor(Color.RED);
chartPoints.getChartPoint(7).getBorder().setColor(Color.WHITE);
chartPoints.getChartPoint(8).getBorder().setColor(Color.YELLOW);

Font tfont = new Font();
tfont.setBold(true);
tfont.setColor(Color.BLACK);
tfont.setSize(10);
tfont.setName(“Verdana”);

ValueAxis valueAxis = chart.getValueAxis();
valueAxis.setMinValue(50);
valueAxis.setMaxValue(200);
valueAxis.setMajorUnit(50);
valueAxis.setMinorUnit(50);

chart.getCategoryAxis().setFont(tfont);

ImageOptions imageOptions = new ImageOptions();
imageOptions.setImageFormat(ImageFormat.JPEG);
imageOptions.setFashion(FileFormatType.EXCEL97TO2003);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
chart.toImage(outputStream, imageOptions);
chart.toImage(“img_line_chart.jpg”, imageOptions);
byte[] imageBytes = outputStream.toByteArray();
outputStream.close();

ByteArrayInputStream inputStream = new ByteArrayInputStream(
imageBytes);
Picture picture = new Picture(presentation, inputStream);
inputStream.close();

outputStream = new ByteArrayOutputStream();
workbook.setOleSize(0, 50, 0, 50);
workbook.save(outputStream);
byte[] oleBytes = outputStream.toByteArray();
outputStream.close();

OleObjectFrame oleObjectFrame = slide.getShapes()
.addOleObjectFrame(0, 0,
(int) presentation.getSlideSize().getX(),
(int) presentation.getSlideSize().getY(),
“Excel.Sheet.8”, oleBytes);
oleObjectFrame
.setPictureId(presentation.getPictures().add(picture));

presentation.save(“aspose_slides_line_color.ppt”, SaveFormat.PPT);


Is there any update on this issue? Can you suggest where does the actual problem exists?

Hi Sundhar,

I am working on your issue and will share the information with you soon after my investigation is completed.

Thanks and Regards,

Hi Sundhar,

I have investigated the issue shared by you using your code snippet. I have saved the chart image that you have taken in a separate file. It is same as that is shown in Ole frame of PPT. It seems to be an issue with Aspose.Cells rather than Aspose.Slides for Java as the chart image is taken through Aspose.Cells. I have shared the generated image as well for your reference. I have used the following code snippet to get the chart image in separate file. I will request our Aspose.Cells team to provide further assistance in this regard.

BufferedImage image = ImageIO.read(inputStream);

ImageIO.write(image, "JPEG", new File("D:\\Aspose Data\\aspose_slides_line_color.jpeg"));

Thanks and Regards,

Hi,


This might be an issue with older versions, but it is fixed in the new release v7.0.0:
http://www.aspose.com/community/files/72/java-components/aspose.cells-for-java/entry325010.aspx

We have made several enhancements and introduced many new features that were in there in .NET version of the product. In this release (Aspose.Cells for Java v7.0.0), we have renamed certain APIs set to clean the API structure to match it with Aspose.Cells for .NET. We have some collection classes but their names do not justify them according to .NET standards. Due to these changes, you may need to fix certain parts of your existing code segments when upgrading from your previous version of Aspose.Cells for Java.

I have updated your code segment related to converting to image file using Aspose.Cells for Java API. See the sample code below for your reference. I have also attached the output image and Excel file here.

Sample code:
Workbook workbook = new Workbook();
WorksheetCollection worksheets = workbook.getWorksheets();
worksheets.removeAt(0);
Worksheet dataSheet = worksheets.add(“Data”);
int sid = worksheets.add(SheetType.CHART);
Worksheet chartSheet = worksheets.get(sid);
chartSheet.setName(“Chart”);
chartSheet.setSelected(true);
int i = chartSheet.getCharts().add(ChartType.LINE, 0, 0,15,20);
Chart chart = chartSheet.getCharts().get(i);

Cells cells = dataSheet.getCells();

cells.get(“A1”).putValue(“”);
cells.get(“B1”).putValue(“Total”);
cells.get(“A2”).putValue(“Russia”);
cells.get(“B2”).putValue(100);
cells.get(“A3”).putValue(“England”);
cells.get(“B3”).putValue(140);
cells.get(“A4”).putValue(“Alaska”);
cells.get(“B4”).putValue(195);
cells.get(“A5”).putValue(“France”);
cells.get(“B5”).putValue(175);
cells.get(“A6”).putValue(“Oklahoma”);
cells.get(“B6”).putValue(95);
cells.get(“A7”).putValue(“Sydney”);
cells.get(“B7”).putValue(125);
cells.get(“A8”).putValue(“Columbia”);
cells.get(“B8”).putValue(82);
cells.get(“A9”).putValue(“Berlin”);
cells.get(“B9”).putValue(167);
cells.get(“A10”).putValue(“Thailand”);
cells.get(“B10”).putValue(183);

int index = chart.getNSeries().add(“=Data!B2:B10”, true);
chart.getNSeries().setCategoryData(“=Data!A2:A10”);
chart.getNSeries().get(index).setName(“=Data!” + “B1”);

dataSheet.autoFitColumns();

chart.setSizeWithWindow(false);
chart.setLegendShown(false);

ChartPointCollection chartPoints = chart.getNSeries().get(0).getPoints();
chartPoints.get(0).getBorder().setColor(Color.getBlack());
chartPoints.get(1).getBorder().setColor(Color.getBlue());
chartPoints.get(2).getBorder().setColor(Color.getCyan());
chartPoints.get(3).getBorder().setColor(Color.getLime());
chartPoints.get(4).getBorder().setColor(Color.getMagenta());
chartPoints.get(5).getBorder().setColor(Color.getMaroon());
chartPoints.get(6).getBorder().setColor(Color.getRed());
chartPoints.get(7).getBorder().setColor(Color.getWhite());
chartPoints.get(8).getBorder().setColor(Color.getYellow());

Font tfont = chart.getCategoryAxis().getTickLabels().getFont();
tfont.setBold(true);
tfont.setColor(Color.getBlack());
tfont.setSize(10);
tfont.setName(“Verdana”);

Axis valueAxis = chart.getValueAxis();
valueAxis.setMinValue(50);
valueAxis.setMaxValue(200);
valueAxis.setMajorUnit(50);
valueAxis.setMinorUnit(50);

ImageOrPrintOptions imageOptions = new ImageOrPrintOptions();
imageOptions.setImageFormat(ImageFormat.getJpeg());
imageOptions.setSaveFormat(SaveFormat.EXCEL_97_TO_2003);
chart.toImage(“my_img_line_chart.jpg”, imageOptions);
workbook.save(“my_mysingletseries.xls”);


Thank you.


Thanks everyone…

Now, with cells7.0.0, i don’t find this problem occurring anymore

Sundhar