Applies to: Nevron Chart for .NET

How to export the image of a single chart panel?

This article shows you how to capture the image displayed by a single panel in the chart. This may be useful when you have a chart control containing several charts or gauges and you want to export the image content of a single chart or gauge.

The solution is to clone the panel using serialization (it’s the fastest way) and place it to an off screen chart, which can then be used using the image exporter to export the panel content. In the following code snippet the contents of the first chart in the control is exported to the clipboard as a bitmap.

using System.IO;
using Nevron.Serialization;
using Nevron.Chart.WinForm;
using Nevron.Chart;
using Nevron.GraphicsCore;
using Nevron.Serialization;
using (NChartControl chartControl = new NChartControl())
    NSerializer serializer = new NSerializer();
    MemoryStream memStream = new MemoryStream();
    serializer.SaveToStream(nChartControl1.Charts[0], memStream, PersistencyFormat.Binary, null);
    memStream.Seek(0, SeekOrigin.Begin);
    Type panelType = nChartControl1.Charts[0].GetType();
    NChart chart = (NChart)serializer.LoadFromStream(panelType, memStream, PersistencyFormat.Binary, null);
    chart.Dock = DockStyle.Fill;
    chartControl.ImageExporter.CopyToClipboard(new NSize(200, 200), NResolution.ScreenResolution, new NBitmapImageFormat());

Imports System.IO
Imports Nevron.Serialization
Imports Nevron.Chart.WinForm
Imports Nevron.Chart
Imports Nevron.GraphicsCore
Imports Nevron.Serialization
Using chartControl As New NChartControl()
    Dim serializer As New NSerializer()
    Dim memStream As New MemoryStream()
    serializer.SaveToStream(nChartControl1.Charts(0), memStream, PersistencyFormat.Binary, Nothing)
    memStream.Seek(0, SeekOrigin.Begin)
    Dim panelType As Type = nChartControl1.Charts(0).[GetType]()
    Dim chart As NChart = DirectCast(serializer.LoadFromStream(panelType, memStream, PersistencyFormat.Binary, Nothing), NChart)
    chart.Dock = DockStyle.Fill
    chartControl.ImageExporter.CopyToClipboard(New NSize(200, 200), NResolution.ScreenResolution, New NBitmapImageFormat())
End Using

Article ID: 51, Created On: 10/6/2010, Modified: 11/15/2010