Hi,
We are having the requirement where we want to convert the chart in xls sheet into image.Please let us know how to do it.Sample code will really help.
Thanks
Ravi
Hi,
We are having the requirement where we want to convert the chart in xls sheet into image.Please let us know how to do it.Sample code will really help.
Thanks
Ravi
We are looking for java code to accomplish this.
Hi,
Please try the attached version. We have released a beta version for the feature (Chart-to-Image). We are also enhancing the feature to make it equal to .NET version of the product.
For reference, please see the thread:
I will also paste here the sample code:
import com.aspose.cells.*;import java.io.*;
public class ChartImage {
private static Chart chart;
private static String dir = “e:\files\”;
public static void main( String[] arguments) throws Exception
{
final Workbook wb = new Workbook();
final Worksheet ws = wb.getWorksheets().getActiveSheet();
final Cells c = ws.getCells();
for (int i=1, value=1; i<4; i++)
{
c.getCell(“A” + i).setValue(“R” + i);
for (int j=1; j<5; j++, value++)
c.getCell(CellsHelper.convertColumnIndexToName(j) + i).setValue(value);
}
final Worksheet worksheet = wb.getWorksheets().getActiveSheet();
chart = worksheet.getCharts().addChart(ChartType.COLUMN_CLUSTERED, 5, 1, 18, 4);
drawReportViewerBarChart();
final ImageOptions imgOpts = new ImageOptions();
imgOpts.setImageFormat(ImageFormat.PNG);
try {
chart.toImage(dir + “xchartb1.png”, imgOpts);
} catch (Exception e) {
e.printStackTrace();
}
chart = worksheet.getCharts().addChart(ChartType.PIE, 5, 6, 18, 9);
drawReportViewerPieChart();
try {
chart.toImage(dir + “xchartb2.png”, imgOpts);
} catch (Exception e) {
e.printStackTrace();
}
wb.save(dir + “xchartb2.xls”);
}
private static void drawReportViewerPieChart() throws Exception
{
chart.setType(ChartType.PIE);
chart.getNSeries().add(“Sheet1!$A$1:$E$3”, true);
chart.getPlotArea().getArea().setVisible(false);
drawReportViewerChart();
}
private static void drawReportViewerBarChart() throws Exception
{
chart.setType(ChartType.COLUMN_CLUSTERED);
chart.getNSeries().add(“Sheet1!$A$1:$E$3”, true);
chart.getPlotArea().getArea().setForegroundColor(Color.GRAY);
drawReportViewerChart();
}
private static void drawReportViewerChart() throws Exception
{
chart.getTitle().getFont().setBold(true);
chart.getTitle().getFont().setSize(10);
chart.getPlotArea().getBorder().setVisible(false);
NSeries nSeries = chart.getNSeries();
final int size = nSeries.size();
for (int i = 0; i < size; )
chart.getNSeries().get(i).setName(“C” + ++i);
Legend legend = chart.getLegend();
legend.getFont().setSize(8);
legend.getBorder().setVisible(false);
legend.setPosition(LegendPositionType.BOTTOM);
chart.setLegendShown(true);
CategoryAxis ca = chart.getCategoryAxis();
Font f = ca.getTitle().getFont();
f.setSize(10);
f.setBold(true);
ca.getFont().setBold(false);
ca.getFont().setSize(8);
ca.setMajorTickMark(TickMarkerType.OUTSIDE);
ValueAxis va = chart.getValueAxis();
va.getFont().setBold(false);
va.getFont().setSize(8);
va.setMajorTickMark(TickMarkerType.OUTSIDE);
}
}
Thanks.
Hi,
I have downloaded the sample and tried to execute, its throwing java.lang.UnsupportedClassVersionError: com/aspose/cells/Workbook (Unsupported major.minor version 49.0) exception as my jdk version is 1.4.
Can you please send to me the JDK 1.4 compatible zip which supports this chart-to-image feature.
Thanks
Ravi
Hi Ravi,
We will soon provide you JDK1.4 supported version of Aspose.Cells for Java beta version for Chart-to-Image feature.
Thank you.
Hi Amjad,
I am really sorry to ask this,as to when can I expect this JDK 1.4 compatible library.Our proof of concept is on hold because of this.
Thanks
Ravi
Hi,
Please find attached the zipped file of Aspose.Cells for Java beta release for Chart-to-Image feature. In the archive you can find both versions i.e…, one for JDK1.4 and other for JDK1.5.
Thank you.
Thanks a lot for very quick update.I have never seen such fast updates in any forums.Really impressed.
We will try with JDK 1.4 compatible version and will get back to you for further queries.
Thanks
Ravi
Hi,
Following are the updates from our end.
Thanks
Ravi
Hi Ravi,
Thank you for considering Aspose.
Are you using Aspose.Slides for Java to generate your PPT files? If yes, then you may contact Aspose.Slides team regarding your queries using the following forum link. One of Aspose.Slides developer will reply you soon regarding your queries.
Thank You & Best Regards,
Yes, we are using Aspose slides for generating PPTs.
Hi,
We are getting following error when we are using JDK 1.4 compatible version for chart to image feature.
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x6D1C4610
Function=[Unknown.]
Library=C:\j2sdk1.4.1_02\jre\bin\fontmanager.dll
NOTE: We are unable to locate the function name symbol for the error
just occurred. Please refer to release documentation for possible
reason and solutions.
Current Java thread:
at sun.awt.font.NativeFontWrapper.registerFonts(Native Method)
at sun.java2d.SunGraphicsEnvironment.addPathFonts(SunGraphicsEnvironment.java:736)
at sun.java2d.SunGraphicsEnvironment.registerFonts(SunGraphicsEnvironment.java:587)
at sun.java2d.SunGraphicsEnvironment.access$100(SunGraphicsEnvironment.java:49)
at sun.java2d.SunGraphicsEnvironment$2.run(SunGraphicsEnvironment.java:209)
at java.security.AccessController.doPrivileged(Native Method)
at sun.java2d.SunGraphicsEnvironment.loadFonts(SunGraphicsEnvironment.java:203)
at sun.java2d.SunGraphicsEnvironment.mapFontName(SunGraphicsEnvironment.java:451)
at java.awt.Font.initializeFont(Font.java:313)
at java.awt.Font.(Font.java:345)
at com.aspose.a.n.(Unknown Source)
at com.aspose.a.i.b(Unknown Source)
at com.aspose.a.h.(Unknown Source)
at com.aspose.a.c.a.a(Unknown Source)
at com.aspose.cells.Chart.toImage(Unknown Source)
at ChartImage.main(ChartImage.java:47)
Dynamic libraries:
0x00400000 - 0x00407000 C:\j2sdk1.4.1_02\bin\javaw.exe
0x7C900000 - 0x7C9B2000 C:\WINDOWS\system32\ntdll.dll
0x7C800000 - 0x7C8F6000 C:\WINDOWS\system32\kernel32.dll
0x77DD0000 - 0x77E6B000 C:\WINDOWS\system32\ADVAPI32.dll
0x77E70000 - 0x77F02000 C:\WINDOWS\system32\RPCRT4.dll
0x77FE0000 - 0x77FF1000 C:\WINDOWS\system32\Secur32.dll
0x7E410000 - 0x7E4A1000 C:\WINDOWS\system32\USER32.dll
0x77F10000 - 0x77F59000 C:\WINDOWS\system32\GDI32.dll
0x77C10000 - 0x77C68000 C:\WINDOWS\system32\MSVCRT.dll
0x76390000 - 0x763AD000 C:\WINDOWS\system32\IMM32.DLL
0x10000000 - 0x10011000 C:\WINDOWS\system32\AMINIT.dll
0x10100000 - 0x10166000 C:\WINDOWS\system32\csauser.dll
0x6D340000 - 0x6D46A000 C:\j2sdk1.4.1_02\jre\bin\client\jvm.dll
0x76B40000 - 0x76B6D000 C:\WINDOWS\system32\WINMM.dll
0x6D1E0000 - 0x6D1E7000 C:\j2sdk1.4.1_02\jre\bin\hpi.dll
0x6D310000 - 0x6D31E000 C:\j2sdk1.4.1_02\jre\bin\verify.dll
0x6D220000 - 0x6D239000 C:\j2sdk1.4.1_02\jre\bin\java.dll
0x6D330000 - 0x6D33D000 C:\j2sdk1.4.1_02\jre\bin\zip.dll
0x6D000000 - 0x6D105000 C:\j2sdk1.4.1_02\jre\bin\awt.dll
0x73000000 - 0x73026000 C:\WINDOWS\system32\WINSPOOL.DRV
0x774E0000 - 0x7761D000 C:\WINDOWS\system32\ole32.dll
0x5AD70000 - 0x5ADA8000 C:\WINDOWS\system32\UxTheme.dll
0x6D190000 - 0x6D1E0000 C:\j2sdk1.4.1_02\jre\bin\fontmanager.dll
0x74720000 - 0x7476C000 C:\WINDOWS\system32\MSCTF.dll
0x755C0000 - 0x755EE000 C:\WINDOWS\system32\msctfime.ime
0x77120000 - 0x771AB000 C:\WINDOWS\system32\OLEAUT32.DLL
0x76C90000 - 0x76CB8000 C:\WINDOWS\system32\imagehlp.dll
0x59A60000 - 0x59B01000 C:\WINDOWS\system32\DBGHELP.dll
0x77C00000 - 0x77C08000 C:\WINDOWS\system32\VERSION.dll
0x76BF0000 - 0x76BFB000 C:\WINDOWS\system32\PSAPI.DLL
Local Time = Mon Dec 14 15:32:43 2009
Elapsed Time = 3
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.4.1_02-b06 mixed mode)
#
# An error report file has been saved as hs_err_pid6892.log.
# Please refer to the file for further information.
Hi,
Thank you for considering Aspose.
We will look into it and get back to you soon.
Thank You & Best Regards,
Hi,
Thank you for considering Aspose.
It is a complex issue of JDK1.4 and the OS environment. To get more information about it, please see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4482430. Please upgrade your JDK to some higher versions such as 1.4.2_11. We have tested Chart2Image feature with JDK1.4.2_11 and it works fine.
Thank You & Best Regards,
Hi,
Even after changing the jdk to JDK1.4.2_11 version we are getting the following error.
#<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x03454a07, pid=5092, tid=4152
#
# Java VM: Java HotSpot(TM) Client VM (1.4.2_11-b06 mixed mode)
# Problematic frame:
# C [fontmanager.dll+0x34a07]
#
# An error report file with more information is saved as hs_err_pid5092.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
Thanks
Ravi
Hi,
Thank you for considering Aspose.
It is a complex issue of JDK and the OS environment too. To get more information about it, please see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4762039. We think it is related to special environment because we have tested Chart2Image feature here with JDK1.4.1 and JDK1.4.2 and they all worked well. Did you re-install your JDK completely? I think you can try to clear all installed JDKs from your machine (all files and registered information) and then install a latest version of JDK that you can use and try again.
Thank You & Best Regards.
Hi,
I have uninstalled all the JDK versions and reinstalled JDK1.4.2_11. But still I am getting the error.
# An unexpected error has been detected by HotSpot Virtual Machine:
#EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x03464a07, pid=3392, tid=7840
#Java VM: Java HotSpot(TM) Client VM (1.4.2_11-b06 mixed mode)
# Problematic frame:
# C [fontmanager.dll+0x34a07]
#
# An error report file with more information is saved as hs_err_pid3392.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
Thanks
Ravi
Hi,
Thank you for considering Aspose.
Please try to create some java.awt.Font objects using the settings (name, size, style) of the fonts that are used by the chart? And if you can create those java.awt.Font objects successfully, please send us your excel file that contains the chart to be converted to image and we will further check it (If the Workbook object is newly created by your code, you can use Workbook.save() to save it as a file before invoke Chart.toImage()).
Thank You & Best Regards,
Hi,
We are still facing the same issue.
Please do find the attached java file and the xls file (containing chart which we are trying to convert to image)
Thanks
Ravi
Hi,
Thank you for sharing the files.
We will look into your issue and get back to you soon.
Thank You & Best Regards,