Free Support Forum - aspose.com

Convert Chart to Image for Java - getting beta version

Dear Sir,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I have read in the forum that the beta version for "Convert Chart to Image for Java " is available.

http://www.aspose.com/community/forums/thread/210404.aspx

Can you please send/let me know from where I can download the same.

I am in the process of considering aspose for our project. The main feature we are looking is the generation of charts and embedding in ppt, where the limitation with existing aspose for getting chart image has blocked me in between.

Also, do you support SmartArts like organization charts in aspose.slides for java?

Thanks & Regards

Muhammed


This message was posted using Email2Forum by Laurence.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Muhammed.Karattu:

I have read in the forum that the beta version for "Convert Chart to Image for Java " is available.

http://www.aspose.com/community/forums/thread/210404.aspx

Can you please send/let me know from where I can download the same.

Please try the attached latest version as per your requirement.

Muhammed.Karattu:

Also, do you support SmartArts like organization charts in aspose.slides for java?

Please post your query in Aspose.Slides forum and one of our Aspose.Slides team representatives will reply you soon. Following is the link to Aspose.Slides forum:

http://www.aspose.com/community/forums/aspose.slides-product-family/109/showforum.aspx

Thank You & Best Regards,

Hi,

Please run the example below, which generate Image from a Dual Chart . The generated image has the following issues.
1. The lines coming outside the chart area in the image.
2. The line colors are different from actual line colors in the excel chart.

Sample XLS and PNG files are attached.

Code

import java.io.*;
import java.lang.reflect.Array;
import com.aspose.cells.*;
import com.aspose.slides.*;

public class DualAxisChartMaker {

public static void main(String args[]) {

try {
String[] cellsName = new String[] { "A2", "A3", "A4",
"B2", "B3", "B4",
"C2", "C3", "C4",
"D2", "D3", "D4",
"E2", "E3", "E4",
"F2", "F3", "F4",
"G2", "G3", "G4",
"H2", "H3", "H4"
};

//Array of cell data
int[] cellsValue = new int[] { 60, 80, 60,
67, 86, 68,
44, 64, 89,
46, 97, 78,
43, 29, 69,
24, 40, 38,
40, 90, 70,
42, 92, 72
};

Workbook wb = new Workbook();
Worksheet dataSheet = wb.getWorksheets().addSheet();
wb.getPalette().setColor(55, Color.RED);
wb.getPalette().setColor(54, Color.GREEN);

String dataSheetName = "DataSheet";
dataSheet.setName(dataSheetName);

//Populate DataSheet with data
dataSheet.getCells().getCell("A1").setValue("US");
dataSheet.getCells().getCell("B1").setValue("UK");
dataSheet.getCells().getCell("C1").setValue("Italy");
dataSheet.getCells().getCell("D1").setValue("Japan");
dataSheet.getCells().getCell("E1").setValue("India");
dataSheet.getCells().getCell("F1").setValue("Canada");
dataSheet.getCells().getCell("G1").setValue("Brazil");
dataSheet.getCells().getCell("H1").setValue("Mexico");

int size = Array.getLength(cellsName);
for (int i = 0; i < size; i++) {
String cellName = cellsName[i];
int cellValue = cellsValue[i];
dataSheet.getCells().getCell(cellName).setValue(cellValue);
}

//Add a chart sheet
Worksheet chartSheet = wb.getWorksheets().addSheet();
chartSheet.setName("ChartSheet");
int chartSheetIdx = chartSheet.getIndex();

//Add a chart in ChartSheet with data series from DataSheet
int chartRows = 25, chartCols = 15;
Chart chart = chartSheet.getCharts().addChart(ChartType.COLUMN_CLUSTERED, 0, 0, 1, 1, 500, 400);

chart.getNSeries().add(dataSheetName + "!B2:H4", false);

chart.getNSeries().get(0).setGapWidth(1);

chart.getNSeries().get(1).setPlotOnSecondAxis(true);
chart.getNSeries().get(1).setType(ChartType.LINE);
chart.getNSeries().get(1).getBorder().setColor(wb.getPalette().getColor(54));

chart.getNSeries().get(2).setPlotOnSecondAxis(true);
chart.getNSeries().get(2).setType(ChartType.LINE);
chart.getNSeries().get(2).getBorder().setColor(wb.getPalette().getColor(55));

String categoryAreaRef = dataSheetName + "!A1:H1";
chart.getNSeries().setCategoryData(categoryAreaRef);
chart.getNSeries().setSecondCategoryData(categoryAreaRef);

//Get Chart as image.
ImageOptions imgOpts = new ImageOptions();
imgOpts.setImageFormat(ImageFormat.PNG);
imgOpts.setFashion(FileFormatType.EXCEL2003);

chart.toImage(new FileOutputStream("D:\\Temp\\chart.png"), imgOpts);

wb.getWorksheets().setActiveSheet(chartSheetIdx);
wb.setOleSize(0, chartRows, 0, chartCols);

//Save the workbook to stream
ByteArrayOutputStream bout = new ByteArrayOutputStream();
wb.save(bout);
wb.save(new FileOutputStream("D:\\Temp\\output.xls"));

Presentation pres = new Presentation();
Slide sld = pres.addEmptySlide();

int slideWidth = (int) pres.getSlideSize().getX() - 1500;

int slideHeight = (int) pres.getSlideSize().getY();
int x = 1500 / 2;
OleObjectFrame oof = sld.getShapes().addOleObjectFrame(x, 0, slideWidth, slideHeight, "Excel.Sheet.8", bout.toByteArray());

com.aspose.slides.Picture pic = new com.aspose.slides.Picture(pres, new FileInputStream("D:\\Temp\\chart.png"));
int picId = pres.getPictures().add(pic);
oof.setPictureId(picId);

//Write the presentation on disk
pres.write(new FileOutputStream("D:\\Temp\\output.ppt"));
System.out.println("successfully completed!!!");

}
catch (Exception e) {
e.printStackTrace();
}
}

}

Thanks
Muhammed

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

We have found your mentioned issue after an initial test. We will look into it and get back to you soon. Your issue has been registered in our internal issue tracking system with issue id CELLSJAVA-14146.

Thank you & Best Regards,

Hi,

Please try the attached version, we have fixed your mentioned issue.

Thank you.

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


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

Thanks

Muhammed