Store the Chart Layout
- 3 minutes to read
This document explains how a chart’s layout can be saved and restored.
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. And, if a chart is bound to a data source, the information about series data members is included, so that when restoring the layout to another chart, you should simply re-assign it’s ChartControl.DataSource property.
Note
We guarantee backward compatibility for a chart layout serialization, meaning that the saved layout will remain fully compatible after migrating to the next XtraCharts version.
You can save and/or restore the layout of your ChartControl or WebChartControl in one of the two following ways.
Save and Restore the Layout at Design Time
At design time, a chart’s layout can be quickly saved to an XML file by clicking the chart’s smart tag and choosing Save… in its actions list.
Then, simply specify the path and name for the XML file.
Afterwards, click a chart’s smart tag and choose Load… in its actions list to restore this layout.
Save and Restore the Layout at Runtime
At runtime, a chart’s layout can be saved either to an XML file or to a memory stream, and then programmatically restored from it. The table below contains methods to store a chart’s layout.
Methods used to save and restore a chart, grouped by platforms, are listed below.
Platform | Member | Description |
---|---|---|
Windows Forms | ChartControl.SaveToFile | Saves the chart’s layout to the specified file. |
ChartControl.SaveToStream | Saves the chart’s layout to the specified stream. | |
ChartControl.LoadFromFile | Restores the chart’s layout from the specified file. | |
ChartControl.LoadFromStream | Restores the chart’s layout from the specified stream. | |
XtraReports | XRChart.SaveToFile | Saves the chart’s layout to the specified file. |
XRChart.SaveToStream | Saves the chart’s layout to the specified stream. | |
XRChart.LoadFromFile | Restores the chart’s layout from the specified file. | |
XRChart.LoadFromStream | Restores 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.
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);