You are viewing help content for pre-release software. This document and the features it describes are subject to change. Switch to the current version.

Save and Load the Chart Layout

  • 3 minutes to read

The Chart Control allows you to save the chart layout to and load it from a file or a stream. Use the following methods for this:

Method Description
LoadFromFile(String) Loads a chart layout from the specified file.
LoadFromStream(Stream) Loads the chart layout from the specified stream.
SaveToFile(String) Saves a chart layout to the specified file.
SaveToStream(Stream) Saves the chart layout to the specified stream.

Serialized data contains information about all configured chart elements. If you add points to a chart’s series, the saved layout contains information about these series points.

When you bind the chart to a data source, the serialized layout includes DataMember properties but does not contain the data source. Bind the chart loaded from the saved layout to an appropriate data source to restore the chart settings correctly. Custom element templates are also not saved to a file or a stream.


DevExpress guarantees backward compatibility for serialized layouts. Saved data remains fully compatible when you migrate to a newer Chart Control version.


Save/Load the Chart Layout from a File

The following code uses the ChartControl.SaveToFile method to save the chart layout to a file, and the ChartControl.LoadFromFile method to restore the layout from a file:

View Example

// In the Window's code-behind file.
const string LayoutSavedFormatString = "The Chart Layout saved to the '{0}' file";
const string LayoutLoadedFormatString = "The Chart Layout loaded from the '{0}' file";

private void OnSaveBarItemClick(object sender, ItemClickEventArgs e) {
    DXSaveFileDialog dialog = new DXSaveFileDialog();
    dialog.DefaultExt = "xml";
    bool? result = dialog.ShowDialog();
    if (result.HasValue && result.Value) {
        statusMessageItem.Content = String.Format(LayoutSavedFormatString, dialog.FileName);

private void OnLoadBarItemClick(object sender, ItemClickEventArgs e) {
    DXOpenFileDialog dialog = new DXOpenFileDialog();
    dialog.DefaultExt = "xml";
    bool? result = dialog.ShowDialog();
    if (result.HasValue && result.Value) {
        // IMPORTANT: LoadFrom... methods create new instances of chart elements to restore the Chart Control's layout.
        // You should recreate bindings if you bind UI controls to chart elements.
        statusMessageItem.Content = String.Format(LayoutLoadedFormatString, dialog.FileName);

Save/Load the Chart Layout from a Stream

The following code saves the chart layout to a stream, and then loads the layout from the stream:

using System.IO;

  Stream stream = new MemoryStream();

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

  // Load the chart.
  stream.Seek(0, System.IO.SeekOrigin.Begin);