Back to Devexpress

Storing the Chart Layout

aspnet-15964-components-chart-control-concepts-creating-charts-miscellaneous-storing-the-chart-layout.md

latest4.7 KB
Original Source

Storing the Chart Layout

  • Dec 17, 2020
  • 3 minutes to read

This topic explains how to save and restore a chart layout.

A chart’s layout contains information about the chart’s series and other elements, as well as their settings.

If chart series are manually populated with points, the layout also includes information on point arguments and values.

If a chart is bound to a data source, the information about series data members is included. Thus, when you restore the layout to another chart, you should reassign the chart’s ASPxDataWebControlBase.DataSource property.

You can save and/or restore the layout of your WebChartControl at design time or runtime.

Save and Restore the Layout at Design Time

At design time, you can can click a chart’s smart tag and choose Save… in the invoked Tasks list to save the chart’s layout to an XML file.

Then, simply specify the path and name for the XML file.

Next, click the chart’s smart tag and select Load… in the invoked Tasks list to restore the layout.

Save and Restore the Layout at Runtime

At runtime, you can save a chart’s layout to an XML file or to a memory stream, and restore it programmatically.

The following table lists methods used to save and restore a chart - grouped by platform.

PlatformMemberDescription
ASP.NETWebChartControl.SaveToFileSaves the chart’s layout to the specified file.
WebChartControl.SaveToStreamSaves the chart’s layout to the specified stream.
WebChartControl.LoadFromFileRestores the chart’s layout from the specified file.
WebChartControl.LoadFromStreamRestores the chart’s layout from the specified stream.
ASP.NET MVCChartControlSettings.SaveToFileSaves the chart’s layout to the specified file.
ChartControlSettings.SaveToStreamSaves the chart’s layout to the specified stream.
ChartControlSettings.LoadFromFileRestores the chart’s layout from the specified file.
ChartControlSettings.LoadFromStreamRestores the chart’s layout from the specified stream.
XtraReportsXRChart.SaveToFileSaves the chart’s layout to the specified file.
XRChart.SaveToStreamSaves the chart’s layout to the specified stream.
XRChart.LoadFromFileRestores the chart’s layout from the specified file.
XRChart.LoadFromStreamRestores the chart’s layout from the specified stream.

The following example demonstrates how to save a chart to a memory stream, and then restore it.

csharp
using System.IO;
// ...

Stream stream = new MemoryStream();
// ...

// Save the chart.
stream.Seek(0, System.IO.SeekOrigin.Begin);
chartControl1.SaveToStream(stream);

// Load the chart.
stream.Seek(0, System.IO.SeekOrigin.Begin);
chartControl1.LoadFromStream(stream);
vb
Imports System.IO
' ...

Dim stream As System.IO.Stream
stream = New System.IO.MemoryStream()
' ...

' Save the chart.
stream.Seek(0, System.IO.SeekOrigin.Begin)
ChartControl1.SaveToStream(stream)

' Load the chart.
stream.Seek(0, System.IO.SeekOrigin.Begin)
ChartControl1.LoadFromStream(stream)

See Also

How to: Export a Chart