Skip to main content
All docs
V24.1

DataSourceAdapter.DataSource Property

SECURITY NOTE

Deserializing layout settings from untrusted resources may create security issues. Serializable System.Object properties that contain custom type values are not (de)serialized automatically. Review the following help topic for information on how to (de)serialize custom type values: Safe Deserialization.

Gets or sets the data source used to create series points.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v24.1.dll

NuGet Package: DevExpress.Charts

Declaration

[NonTestableProperty]
[TypeConverter(typeof(DataSourceConverter))]
[XtraChartsLocalizableCategory(XtraChartsCategory.Data)]
[XtraSerializableProperty(XtraSerializationVisibility.Reference)]
public object DataSource { get; set; }

Property Value

Type Description
Object

The data source.

Remarks

You can assign an object that implements any of the following interfaces:

Example

This example shows how to create a series that requires one value per argument and populate it with data.

using DevExpress.Utils;
using DevExpress.XtraCharts;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace ChartDataAdapters {
    public partial class Form1 : Form {
        readonly TemperatureData temperatureData = new TemperatureData(new Random(9));
        public Form1() {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e) {
            // Create a series.
            Series series = new Series("Temperature", ViewType.Spline);

            // Create a data adapter.
            DataSourceAdapter dataAdapter = new DataSourceAdapter();

            // Specify the data source.
            dataAdapter.DataSource = temperatureData.Points;

            // Create a data member that defines arguments.
            dataAdapter.DataMembers.Add(new DataMember {
                DataMemberType = ChartDataMemberType.Argument,
                ColumnName = "TimeStamp",
                ScaleType = ScaleType.TimeSpan
            });
            // Create a data member that defines values.
            dataAdapter.DataMembers.Add(new DataMember {
                DataMemberType = ChartDataMemberType.Value,
                ColumnName = "Temperature",
                ScaleType = ScaleType.Numerical
            });

            // Assign the data adapter to the series.
            series.DataAdapter = dataAdapter;
        }
    }
    class TemperatureData {
        const int PointsCount = 250;
        readonly TemperaturePoint maxTemperaturePoint = new TemperaturePoint(TimeSpan.Zero, double.MinValue);
        readonly TemperaturePoint minTemperaturePoint = new TemperaturePoint(TimeSpan.MaxValue, double.MaxValue);
        readonly List<TemperaturePoint> points = new List<TemperaturePoint>(PointsCount);
        internal TemperaturePoint MaxTemperaturePoint {
            get { return maxTemperaturePoint; }
        }
        internal TemperaturePoint MinTemperaturePoint {
            get { return minTemperaturePoint; }
        }
        internal double OptimalTemperature {
            get { return 53; }
        }
        internal List<TemperaturePoint> Points {
            get { return points; }
        }
        internal TemperatureData(Random random) {
            double preTemperature = 50;
            for (int i = 0; i < PointsCount; i++) {
                TimeSpan time = TimeSpan.FromSeconds(i);
                double temperature = preTemperature + (random.NextDouble() - 0.5) * 10;
                if (temperature > 90)
                    temperature -= 20;
                if (temperature < 20)
                    temperature += 10;
                TemperaturePoint temperaturePoint = new TemperaturePoint(time, temperature);
                if (temperature < minTemperaturePoint.Temperature)
                    minTemperaturePoint = temperaturePoint;
                if (temperature > maxTemperaturePoint.Temperature)
                    maxTemperaturePoint = temperaturePoint;
                points.Add(temperaturePoint);
                preTemperature = temperature;
            }
        }
    }
    public class TemperaturePoint {
        public TimeSpan TimeStamp { get; private set; }
        public double Temperature { get; private set; }

        internal TemperaturePoint(TimeSpan time, double temperature) {
            this.TimeStamp = time;
            this.Temperature = temperature;
        }
    }
}
See Also