Exporting in .NET MAUI Polar Chart
15 Jul 20262 minutes to read
Export as an image
You can export the chart view as an image in the desired file format using the SaveAsImage method of SfPolarChart. The supported image formats are JPEG and PNG. By default, if you don’t mention any image format with the filename, the chart view will be exported as an image in the PNG format.
NOTE
Prerequisite: Ensure that the required NuGet package is installed, the necessary namespaces are imported, and the SfPolarChart control is properly configured in your application. For detailed setup and configuration instructions, refer to the Getting Started guide.
NOTE
The chart view can be exported as an image only when the chart view is added to the visual tree.
The following code sample demonstrates the usage of this method:
SfPolarChart chart = new SfPolarChart();
// code omitted for brevity
this.Content = chart;
chart.SaveAsImage("ChartSample.jpeg");TIPS
We can change the image formats in the above code by changing their extensions to .jpg or .png.
The exported image will be saved in different locations across platforms:
- Windows and Android – The image will be saved in the device’s Pictures directory.
- iOS – The image will be saved in the Photos/Album directory.
- macOS – The image will be saved in the designated Pictures folder.
To save images on Android and Windows devices, enable file writing permissions in the device storage.
To save images in the photo album on iOS devices, enable photo library access by adding the following keys to the Info.plist file:
<dict>
<!-- code omitted for brevity -->
<key>NSPhotoLibraryUsageDescription</key>
<string>This App needs permission to access the Photos</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>This App needs permission to access the Photos</string>
<!-- code omitted for brevity -->
</dict>Get the stream of Chart
The GetStreamAsync method of SfPolarChart is used to asynchronously get the chart view as a stream in the desired ImageFileFormat. The output stream can be passed as an input to other components that accept streams, such as PDF, Excel, and Word. The supported image file formats are JPEG and PNG.
NOTE
The charts stream can only be rendered when the chart view is added to the visual tree.
The following code sample demonstrates the usage of this method:
SfPolarChart chart = new SfPolarChart();
// code omitted for brevity
this.Content = chart;
await chart.GetStreamAsync(ImageFileFormat.Jpeg);NOTE
You can refer to our .NET MAUI Charts feature tour page for its groundbreaking feature representations. You can also explore our .NET MAUI Charts example to knows various chart types and how to easily configured with built-in support for creating stunning visual effects.