ComponentOne FlexChart for WinForms
Export to Image
FlexChart > Working with FlexChart > Export > Export to Image

FlexChart for WinForms allows you to export the chart to multiple image formats. The supported formats are PNG, JPEG, and SVG.

To export a FlexChart to an image format, use SaveImage method. The method saves the chart as an image to the specified stream in the given ImageFormat. You can optionally specify the height, width, and back color of the image to be saved.

This topic uses the sample created in Quick Start topic to explain the implementation for exporting a FlexChart to an image on button click event.

The following image shows a chart with a button to be clicked to export chart to a desired image format.


 To export a chart to image on button click use the following code.

Private Sub button1_Click(sender As Object, e As EventArgs)
    Dim dialog = New SaveFileDialog() With {
            Key.Filter = "PNG|*.png|JPEG |*.jpeg|SVG|*.svg"
    }
    If dialog.ShowDialog() = DialogResult.OK Then
        Using stream As Stream = dialog.OpenFile()
            Dim extension = dialog.FileName.Split("."c)(1)
            Dim fmt As ImageFormat = DirectCast([Enum].Parse(GetType(ImageFormat), extension, True), ImageFormat)
            FlexChart1.SaveImage(stream, fmt, 500, 800)
        End Using
    End If
End Sub
private void button1_Click(object sender, EventArgs e)
{
    var dialog = new SaveFileDialog()
    {
        Filter = "PNG|*.png|JPEG |*.jpeg|SVG|*.svg"
    };
    if (dialog.ShowDialog() == DialogResult.OK)
    {
        using (Stream stream = dialog.OpenFile())
        {
            var extension = dialog.FileName.Split('.')[1];
            ImageFormat fmt = (ImageFormat)Enum.Parse(typeof(ImageFormat), extension, true);
            flexChart1.SaveImage(stream, fmt, 500, 800);
        }
    }
}
See Also

FlexChart Quick Start

Reference