Skip to main content
A newer version of this page is available. .

ChartControl.SaveToFile(String) Method

Saves the chart layout to the specified file.

Namespace: DevExpress.Xpf.Charts

Assembly: DevExpress.Xpf.Charts.v19.1.dll

Declaration

public void SaveToFile(
    string fileName
)

Parameters

Name Type Description
fileName String

The path to the file where the layout should be stored. An exception is raised if an empty string is specified.

Remarks

The SaveToFile method saves the chart layout (information about available series, series settings, etc.) to a specified file. Use the ChartControl.LoadFromFile method to restore saved settings from this file.

Example

The following code utilizes the save/load methods, and allows an end user to write to or read from a layout file:

Tip

The complete example is available on GitHub.

// 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) {
        chartControl.SaveToFile(dialog.FileName);
        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) {
        chartControl.LoadFromFile(dialog.FileName);
        // 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.
        CreateBindings();
        statusMessageItem.Content = String.Format(LayoutLoadedFormatString, dialog.FileName);
    }
}

The Chart Control provides the following methods that save/load its layout:

Method

Description

SaveToFile(String)

Saves the chart layout to the specified file.

SaveToStream(Stream)

Saves the chart layout to the specified stream.

LoadFromFile(String)

Loads the chart layout from the specified file.

LoadFromStream(Stream)

Loads the chart layout from the specified stream.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SaveToFile(String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also