Skip to main content
All docs
V24.1

ISeriesTemplateAdapter Interface

Should be implemented by any class that can be used as a data adapter that creates series based on a template.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v24.1.dll

NuGet Package: DevExpress.Charts

Declaration

[TypeConverter(typeof(LocalizableExpandableObjectTypeConverter))]
public interface ISeriesTemplateAdapter :
    IChartDataAdapter,
    ICloneable

The following members return ISeriesTemplateAdapter objects:

Remarks

The following example shows how to implement a series template adapter. This adapter is used to create two series with numeric arguments and values:

using DevExpress.XtraCharts;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace CustomDataAdapter {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e) {
            List<DataItem> dataItems = new List<DataItem>() {
                new DataItem(1,1,"I"),
                new DataItem(2,2,"I"),
                new DataItem(3,3,"I"),
                new DataItem(4,4,"I"),
                new DataItem(5,5,"I"),
                new DataItem(1,5,"II"),
                new DataItem(2,4,"II"),
                new DataItem(3,3,"II"),
                new DataItem(4,2,"II"),
                new DataItem(5,1,"II")
            };
            chartControl1.SeriesTemplate.DataAdapter = new CustomNumericDataAdapter(dataItems);
            chartControl1.SeriesTemplate.ChangeView(ViewType.StepLine);
        }
    }
    public class DataItem {
        public double Argument { get; }
        public double Value { get; }
        public string Category { get; }
        public DataItem(double argument, double value, string category) {
            Argument = argument;
            Value = value;
            Category = category;
        }
    }
    public class CustomNumericDataAdapter : ISeriesTemplateAdapter {
        readonly IList<DataItem> items;
        public bool DataSorted => true;
        public int ItemsCount => this.items.Count;
        public CustomNumericDataAdapter(IList<DataItem> items) {
            this.items = items;
        }
        event NotifyChartDataChangedEventHandler IChartDataAdapter.DataChanged {
            add { }
            remove { }
        }
        public object Clone() {
            return this;
        }
        public double GetNumericalValue(int index, ChartDataMemberType dataMember) {
            switch (dataMember) {
                case ChartDataMemberType.Argument: return items[index].Argument;
                case ChartDataMemberType.Value: return items[index].Value;
            }
            return double.NaN;
        }
        public object GetSourceObject(int index) {
            return this.items[index];
        }
        public ActualScaleType GetScaleType(ChartDataMemberType dataMember) {
            return ActualScaleType.Numerical;
        }
        public object GetObjectValue(int index, ChartDataMemberType dataMember) {
            return dataMember is ChartDataMemberType.Series ? items[index].Category : string.Empty;
        }
        public DateTime GetDateTimeValue(int index, ChartDataMemberType dataMember) {
            throw new NotImplementedException();
        }
        public string GetQualitativeValue(int index, ChartDataMemberType dataMember) {
            throw new NotImplementedException();
        }
        public TimeSpan GetTimeSpanValue(int index, ChartDataMemberType dataMember) {
            throw new NotImplementedException();
        }
    }
}
See Also