Converting Chart to Image in SVG Format
Scalable Vector Graphics (SVG) is an XML-based vector image format for two-dimensional graphics that also supports interactivity and animation. The SVG specification is an open standard developed by the World Wide Web Consortium (W3C) since 1999.
SVG images and their behaviors are defined in XML text files. This means that they can be searched, indexed, scripted, and compressed. As XML files, SVG images can be created and edited with any text editor, but are more often created with drawing software.
Aspose.Cells for Python via .NET can save chart into images in various formats like BMP, JPEG, PNG, GIF, SVG etc. This article explains how to save a chart to SVG format.
The following sample code explains how to use Aspose.Cells for Python via .NET to convert a chart into an SVG format image. The code loads the source Microsoft Excel file and then saves the first chart found on the first worksheet to SVG.
from aspose.cells import Workbook | |
from aspose.cells.drawing import ImageType | |
from aspose.cells.rendering import ImageOrPrintOptions | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create workbook object from source file | |
workbook = Workbook(dataDir + "SampleChartBook.xlsx") | |
# Access first worksheet | |
worksheet = workbook.worksheets[0] | |
# Access first chart inside the worksheet | |
chart = worksheet.charts[0] | |
# Set image or print options | |
opts = ImageOrPrintOptions() | |
opts.image_type = ImageType.SVG | |
# Save the chart to svg format | |
chart.to_image(dataDir + "Image_out.svg", opts) |