Chart Vector Image Export
In This Topic
NOV Chart for .NET has integrated support for vector image export that is exposed by the NChartVectorImageExporter class. It lets you export the content of a chart (or portions of it) to a vector image in one of the supported vector image formats. Currently, the supported vector image formats are:
- Scalable Vector Graphics (SVG)
- Enhanced Metafile (EMF)
- AutoCAD Drawing Interchange (DXF)
Saving with a Dialog
The following code shows how to display the vector image export dialog, that allows the user to pick the vector image export format:
Showing the default vector image export dialog |
Copy Code
|
NChartVectorImageExporter imageExporter = new NChartVectorImageExporter(chartView.Content);
imageExporter.ShowDialog(DisplayWindow, true);
|
The following code shows a save image file dialog that allows the user to create a vector image from the chart:
Saving with a save file dialog |
Copy Code
|
NChartVectorImageExporter imageExporter = new NChartVectorImageExporter(chartView.Content);
imageExporter.SaveAsImage(ENVectorImageFormat.Svg); // Save to image with SVG file format selected by default
|
Saving to File or Stream
To export the chart to a vector image and save it directly to a file, without showing a save file dialog, you can use the SaveToFile method. Note that the saving to a file is an asynchronous (async) operation, so if you are interested in its completion, you should call the Then method of the promise it returns and handle the completion of the export in the passed delegate. The following is a code example:
Saving to a file |
Copy Code
|
NChartVectorImageExporter imageExporter = new NChartVectorImageExporter(chartView.Content);
imageExporter.SaveToFileAsync("C:\\ExportedImage.svg").Then(
delegate (NUndefined ud)
{
// Export to SVG completed
}
);
|
Exporting a chart to an arbitrary file works only on non-sandboxed platforms like WinForms, WPF, and Xamarin.Mac.
To export a chart to a vector image stream, you can use the SaveToStream method. Unlike the SaveToFile method, the SaveToStream method runs synchronously and blocks code execution until it completes. Exporting charts to a stream is useful when you wish to generate images in memory instead of saving them to the disc. The following code snippet shows how to export a chart to a stream:
Saving to a stream |
Copy Code
|
NChartVectorImageExporter imageExporter = new NChartVectorImageExporter(chartView.Content);
imageExporter.SaveToStream(stream, ENVectorImageFormat.Svg);
|
Generating a Vector Image
To generate an SVG document on the fly without saving it, you should use the CreateSvg method:
Generating image |
Copy Code
|
NChartVectorImageExporter imageExporter = new NChartVectorImageExporter(chartView.Content);
NSvgDocument svgDocument = imageExporter.CreateSvg();
|
You can use the CreateEmf and CreateDxf methods to create EMF byte arrays and DXF documents, respectively.
Copying to Clipboard
To copy the vector image to the clipboard, you should use the CopyToClipboard method:
Generating image |
Copy Code
|
NChartVectorImageExporter imageExporter = new NChartVectorImageExporter(chartView.Content);
imageExporter.CopyToClipboard(ENVectorImageFormat.Svg);
|
The CopyToClipboard method in the case of EMF, places it in the clipboard and for SVG and AutoCAD DXF places their source code in the clipboard.
See Also