Skip to main content
All docs
V24.1

ChartObject.LoadTemplate(Stream) Method

Loads a custom chart style and formatting settings from the stream and applies it to the chart.

Namespace: DevExpress.Spreadsheet.Charts

Assembly: DevExpress.Spreadsheet.v24.1.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

void LoadTemplate(
    Stream stream
)

Parameters

Name Type Description
stream Stream

A stream that contains a chart template in CRTX format.

Remarks

A CRTX file contains a chart template that can be applied to a Chart object or added to ChartCollection as a new chart in the Spreadsheet control. The file stores settings for colors, axes, series, gridlines, categories, legends, text, and other chart options. CRTX files are used to apply the same styles and formatting to multiple charts.

The following code snippet applies a chart template from a .CRTX file to an existing chart:

using DevExpress.Spreadsheet.Charts;
using System.IO;
// ...
spreadsheetControl1.LoadDocument("Document.xlsx");
// Create a chart.
DevExpress.Spreadsheet.Charts.Chart chart1 = spreadsheetControl1.ActiveWorksheet.Charts.Add(ChartType.ColumnClustered, 
spreadsheetControl1.ActiveWorksheet["A21:B32"]);
chart1.TopLeftCell = spreadsheetControl1.ActiveWorksheet.Cells["D20"];
chart1.BottomRightCell = spreadsheetControl1.ActiveWorksheet.Cells["K34"];
// Apply the chart template to the created chart.
using (FileStream stream = new FileStream("Chart1.crtx", FileMode.Open)) {
  chart1.LoadTemplate(stream)
}

The image below illustrates the result:

Load a chart from .CRTX

Limitations

  • Excel 2016 charts are not supported.

Chart templates do not store series data, but do store chart series settings (for example, series type and number). Since a chart template defines series, it may require sufficient data to populate them. The number of chart series must correspond to the number of series stored in the chart template for the following chart types:

  • Surface chart.

    A surface chart must contain at least two series.

  • Stock charts.

    The number of series must correspond to the stock chart type:

    • High-Low-Close
    • Open-High-Low-Close
    • Volume-High-Low-Close
    • Volume-Open-High-Low-Close
See Also