Skip to main content
All docs
V25.1
  • ChartCollection.AddFromTemplate(Stream, CellRange) Method

    Loads a chart template from the stream, binds it to data from the specified range, and adds the chart to the collection.

    Namespace: DevExpress.Spreadsheet.Charts

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

    NuGet Package: DevExpress.Spreadsheet.Core

    Declaration

    Chart AddFromTemplate(
        Stream stream,
        CellRange range
    )

    Parameters

    Name Type Description
    stream Stream

    A stream that contains a chart template in .CRTX format.

    range CellRange

    A CellRange that contains chart data.

    Returns

    Type Description
    Chart

    The created chart object.

    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 shows how to add a chart from a .CRTX file to a workbook:

    using DevExpress.Spreadsheet.Charts;
    using System.IO;
    // ...
    spreadsheetControl1.LoadDocument("Document.xlsx");
    using (FileStream stream = new FileStream("Chart1.crtx", FileMode.Open)) {
        var chart = spreadsheetControl1.ActiveWorksheet.Charts.AddFromTemplate(stream, 
        spreadsheetControl1.ActiveWorksheet["A21:B32"]);
    }
    

    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 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 following chart types are affected:

      • A Stock chart.
      • A Surface chart.

      For example, to populate a High-Low-Close Stock chart, values should be arranged in the following order: high price, low price, closing price.

    See Also