How to Convert Charts in Excel Files to Image Files inside Java Apps

This technical tip show how java developers can Convert Charts in Excel Files to Image Files using Aspose.Cells for Java. Charts are visually appealing and make it easy for users to see comparisons, patterns, and trends in data.

The following technical tip show how developers can Convert Chart to Image using Aspose.Cells component. Charts are visually appealing and make it easy for users to see comparisons, patterns, and trends in data. For instance, rather than analyzing columns of worksheet numbers, a chart shows at a glance whether sales are falling or rising, or how actual sales compare to projected sales. People are frequently asked to present statistical and graphical information in an easy to understand and an easy to maintain manner. A picture helps. Sometimes, charts are needed in an application or web pages. Or it might be needed needed for a Word document, a PDF file, a PowerPoint presentation or some other application. In each case, you want to render the chart as an image so that you can use it elsewhere. Aspose.Cells for Java has supported converting charts in Excel files to image files since release 2.1.2.


The following example shows how to convert a chart to render an image file.


[Java]



//Create a new Workbook.
Workbook workbook = new Workbook();

//Get the first worksheet.
Worksheet sheet = workbook.getWorksheets().get(0);

//Set the name of worksheet
sheet.setName("Data");

//Get the cells collection in the sheet.
Cells cells = workbook.getWorksheets().get(0).getCells();

//Put some values into a cells of the Data sheet.
cells.get("A1").setValue("Region");
cells.get("A2").setValue("France");
cells.get("A3").setValue("Germany");
cells.get("A4").setValue("England");
cells.get("A5").setValue("Sweden");
cells.get("A6").setValue("Italy");
cells.get("A7").setValue("Spain");
cells.get("A8").setValue("Portugal");
cells.get("B1").setValue("Sale");
cells.get("B2").setValue(70000);
cells.get("B3").setValue(55000);
cells.get("B4").setValue(30000);
cells.get("B5").setValue(40000);
cells.get("B6").setValue(35000);
cells.get("B7").setValue(32000);
cells.get("B8").setValue(10000);

//Create chart
intchartIndex = sheet.getCharts().add(ChartType.COLUMN, 12, 1, 33, 12);
Chart chart = sheet.getCharts().get(chartIndex);

//Set properties of chart title
chart.getTitle().setText("Sales By Region");
chart.getTitle().getTextFont().setBold(true);
chart.getTitle().getTextFont().setSize(12);

//Set properties of nseries
chart.getNSeries().add("Data!B2:B8", true);
chart.getNSeries().setCategoryData("Data!A2:A8");

//Set the fill colors for the series's data points (France - Portugal(7 points))
ChartPointCollectionchartPoints = chart.getNSeries().get(0).getPoints();

ChartPoint point = chartPoints.get(0);
point.getArea().setForegroundColor(Color.getCyan());

point = chartPoints.get(1);
point.getArea().setForegroundColor(Color.getBlue());

point = chartPoints.get(2);
point.getArea().setForegroundColor(Color.getYellow());

point = chartPoints.get(3);
point.getArea().setForegroundColor(Color.getRed());

point = chartPoints.get(4);
point.getArea().setForegroundColor(Color.getBlack());

point = chartPoints.get(5);
point.getArea().setForegroundColor(Color.getGreen());

point = chartPoints.get(6);
point.getArea().setForegroundColor(Color.getMaroon());

//Set the legend invisible
chart.setShowLegend(false);

//Get the Chart image
ImageOrPrintOptionsimgOpts = new ImageOrPrintOptions();
imgOpts.setImageFormat(ImageFormat.getPng());

//Save the chart image file.
chart.toImage(new FileOutputStream("D:\\Files\\MyChartImage.png"), imgOpts);


Overview: Aspose.Pdf for Java


Aspose.Cells is a Java component for spreadsheet reporting without using Microsoft Excel. Other features include creating spreadsheets, opening encrypted excel files, macros, VBA, unicode, formula settings, pivot tables, importing data from JDBC ResultSet and support of CSV, SpreadsheetML, PDF, ODS and all file formats from Excel 97 to Excel 2007. It is compatible with Windows, Linux & Unix and supports all advanced features of data management, formatting, worksheet, charting and graphics.


More about Aspose.Cells for Java


- Homepage of Aspose.Cells for Java: http://www.aspose.com/java/excel-component.aspx

- Download Aspose.Cells for Java: http://www.aspose.com/community/files/72/java-components/aspose.cells-for-java/default.aspx

- More Technical Tips Using Aspose.Cells for Java: http://www.aspose.com/docs/display/cellsjava/Technical+Articles




Contact Details

Company Name: Aspose Pty Ltd
Issued By: Zeeshan Ahmed
Phone: 888.277.6734
Address: Suite 163, 79 Longueville Road
City: Lane Cove
State: NSW
Zip: 2066
Country: Australia
Website: Visit the website

Keywords : Convert Chart to Image, Chart to Image conversion, Create Excel chart, Excel Chart to Image, render chart as an image, converting charts in Excel files, charts in Excel, interactive graphical representation, Aspose.Cells for Java, xlsx files, Named Range, Popup event, Imports a worksheet, selected ranges, Formula Calculation Engine, opening xlsx files in java,

by Zeeshan Ahmed (few years ago!)

Latest Press Releases

The Mad Hatter Now Offer a Full Line of Hearth Products and Full Line of Grills

Diabetes Insulin Delivery Pens Market Research Report 2018

Dr Kapadia Provides Tips to Patients Interested in Hair Transplant Procedures

love vashikaran specialist

Solar Blanket Sales Market Report 2018

Spring Bottled Water Market Insights, Forecast to 2025

Biochemical Incubator Sales Market Report 2018

Quinine Sulphate Sales Market Report 2018

Automotive Chassisc System Market Insights, Forecast to 2025

2,6-Dicarboxypyridine market size in key regions like North America, Europe, Asia Pacific an..

Remove this press release ?

Due to extra work required to remove the press-releases we have started charging $1.99 for press release removal.

Your press release will be removed in 24 hours, once the payment has been received.

Search Press Release
e.g. Business, Computer, etc.