DataSourceAdapter Class
An adapter that loads data from a source to the series.
Namespace: DevExpress.XtraCharts
Assembly: DevExpress.XtraCharts.v24.2.dll
Declaration
public class DataSourceAdapter :
DataSourceAdapterBase,
ISeriesAdapter,
IChartDataAdapter,
ICloneable
Example
This example shows how to create a series that requires one value per argument and populate it with data.
- Create a
DataSourceAdapter
object. - Define the adapter DataSourceAdapter.DataSource property.
- Populate the adapter DataSourceAdapterBase.DataMembers collection. You should specify data members that contain arguments and values.
- Use the Series.DataAdapter property to assign the adapter to the series.
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;
}
}
}
Inheritance
See Also