Skip to main content
All docs
V24.1

SeriesTemplateAdapter Class

An adapter that creates series based on a template.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v24.1.dll

NuGet Package: DevExpress.Charts

Declaration

public class SeriesTemplateAdapter :
    DataSourceAdapterBase,
    ISeriesTemplateAdapter,
    IChartDataAdapter,
    ICloneable,
    IAssignableAdapter

Remarks

The SeriesTemplateAdapter creates series based on the chart control’s DataSource.

For more information, see the following section: Load Data.

Examples

The following example shows how to create multiple series based on a template:

Chart series generated based on a template.

  • Specify the chart control’s DataSource property.
  • Create a SeriesTemplateAdapter object.
  • Populate the adapter DataSourceAdapterBase.DataMembers collection. You should specify data members that contain series names, arguments, and values.
  • Use the SeriesTemplate.DataAdapter property to assign the adapter to the chart.
using DevExpress.XtraCharts;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace SeriesTempateAdapters {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();

            // Create a data source object and assign it to the chart.
            SalesData data = new SalesData();
            chartControl1.DataSource = data.Points;

            // Create a data adapter that generates series based on a template.
            SeriesTemplateAdapter dataAdapter = new SeriesTemplateAdapter();

            // Define a data member that contains series names.
            dataAdapter.DataMembers.Add(new DataMember {
                DataMemberType = ChartDataMemberType.Series,
                ColumnName = "CompanyDivision",
                ScaleType = ScaleType.Qualitative
            });

            // Define a data member that contains arguments.
            dataAdapter.DataMembers.Add(new DataMember {
                DataMemberType = ChartDataMemberType.Argument,
                ColumnName = "Date",
                ScaleType = ScaleType.DateTime
            });

            // Define a data member that contains values.
            dataAdapter.DataMembers.Add(new DataMember {
                DataMemberType = ChartDataMemberType.Value,
                ColumnName = "Total",
                ScaleType = ScaleType.Numerical
            });

            // Assign the adapter to the chart.
            chartControl1.SeriesTemplate.DataAdapter = dataAdapter;

            chartControl1.SeriesTemplate.ChangeView(ViewType.Bar);
            chartControl1.SeriesTemplate.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;

            ((XYDiagram)chartControl1.Diagram).AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Month;
            ((XYDiagram)chartControl1.Diagram).AxisX.Tickmarks.MinorVisible = false;
        }
    }
    class SalesData {
        internal List<DataPoint> Points { get; } = new List<DataPoint>() {
            new DataPoint ( "North", new DateTime(2020, 07, 01), 234 ),
            new DataPoint ( "North", new DateTime(2020, 08, 01), 196 ),
            new DataPoint ( "North", new DateTime(2020, 09, 01), 272 ),
            new DataPoint ( "North", new DateTime(2020, 10, 01), 308 ),
            new DataPoint ( "North", new DateTime(2020, 11, 01), 362 ),
            new DataPoint ( "North", new DateTime(2020, 12, 01), 224 ),

            new DataPoint ( "South", new DateTime(2020, 07, 01), 192 ),
            new DataPoint ( "South", new DateTime(2020, 08, 01), 319 ),
            new DataPoint ( "South", new DateTime(2020, 09, 01), 222 ),
            new DataPoint ( "South", new DateTime(2020, 10, 01), 225 ),
            new DataPoint ( "South", new DateTime(2020, 11, 01), 251 ),
            new DataPoint ( "South", new DateTime(2020, 12, 01), 327 ),

            new DataPoint ( "West", new DateTime(2020, 07, 01), 257 ),
            new DataPoint ( "West", new DateTime(2020, 08, 01), 302 ),
            new DataPoint ( "West", new DateTime(2020, 09, 01), 344 ),
            new DataPoint ( "West", new DateTime(2020, 10, 01), 280 ),
            new DataPoint ( "West", new DateTime(2020, 11, 01), 321 ),
            new DataPoint ( "West", new DateTime(2020, 12, 01), 324 )
        };
    }
    public class DataPoint {
        public string CompanyDivision { get; private set; }
        public DateTime Date { get; private set; }
        public double Total { get; private set; }

        internal DataPoint(string companyDivision, DateTime date, double total) {
            this.CompanyDivision = companyDivision;
            this.Date = date;
            this.Total = total;
        }
    }
}
See Also