Converting Chart to Image in SVG Format

Contents
[ ]

The following sample code explains how to use Aspose.Cells to convert a chart into an SVG format image. The code loads the source Excel file and then saves the first chart found on the first worksheet to SVG.

The following screenshot shows the converted chart image in SVG format created with the sample code.

Output image

todo:image_alt_text

Because SVG is an XML-based format, you can also open the output chart image in a text editor like Notepad as shown in this screenshot.

Output SCG in a text editor

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertCharttoImageinSVGFormat.class);
// Create workbook object from source Excel file
Workbook workbook = new Workbook(dataDir + "sample.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Access the first chart inside the worksheet
Chart chart = worksheet.getCharts().get(0);
// Save the chart into image in SVG format
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.setImageType(ImageType.SVG);
chart.toImage(dataDir + "ChartImage.svg", options);