Exporting in .NET MAUI Funnel Chart

8 Jul 20263 minutes to read

NOTE

Prerequisite: Ensure that the required NuGet package is installed, the necessary namespaces are imported, and the Funnel Chart control is properly configured in your application. For detailed setup and configuration instructions, refer to the Getting Started guide.

Export as an image

You can export the chart view as an image in the desired file format using the SaveAsImage method of SfFunnelChart. The supported image formats are JPEG (.jpeg, .jpg) and PNG (.png). By default, if no format is specified with the filename, the chart view will be exported as a PNG image.

NOTE

The chart view can be exported as an image only when the chart view is added to the visual tree.

The following code snippet demonstrates the usage of this method:

SfFunnelChart chart = new SfFunnelChart()
{
    ItemsSource = new ViewModel().Data,
    XBindingPath = "XValue",
    YBindingPath = "YValue"
};

this.Content = chart;
chart.SaveAsImage("ChartSample.jpeg");

TIPS

Change the file extension (.jpg, .jpeg, or .png) to export in a different image format.

The exported image will be saved in different locations across platforms:

  • Windows and Android — The image is saved in the Pictures directory.
  • macOS and iOS — The image is saved in the Photos/Album directory.

Platform-specific permissions

Windows and Android

To save the image on Android and Windows Phone devices, you must enable file writing permissions on the device storage.

iOS

To save the image to the photo album on iOS devices, add the following permissions to the Info.plist file:

<dict>
    <key>NSPhotoLibraryUsageDescription</key>    
    <string>This app needs permission to access your photos</string>    
    <key>NSPhotoLibraryAddUsageDescription</key>    
    <string>This app needs permission to save to your photo library</string> 
</dict>

If permission is denied by the user, the SaveAsImage method will fail silently. Consider implementing permission handling to notify users of the result.

Get the chart as a stream

The GetStreamAsync method of SfFunnelChart asynchronously returns the chart view as a Stream in the desired ImageFileFormat. The output stream can be passed to other components that accept streams, such as PDF, Excel, and Word. The supported image file formats are JPEG (.jpeg, .jpg) and PNG (.png).

NOTE

The chart stream can only be rendered when the chart view is added to the visual tree.

The following code snippet demonstrates the usage of this method:

SfFunnelChart chart = new SfFunnelChart()
{
    ItemsSource = new ViewModel().Data,
    XBindingPath = "XValue",
    YBindingPath = "YValue"
};

this.Content = chart;
Stream stream = await chart.GetStreamAsync(ImageFileFormat.Jpeg);