Skip to main content
All docs
V24.2

ResamplingDataAdapter Class

An adapter that loads data from a source and applies the resampling algorithm to the series.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v24.2.dll

Declaration

public class ResamplingDataAdapter :
    CachedPointDataAdapter,
    IViewportChangedNotifiable

Remarks

An internal data resampling algorithm allows the chart to avoid unnecessary operations when rendering series. The chart renders the minimum set of points required to display the correct series shape and form. The algorithm discards all points that have no effect on the output (for example, overlapped points). Every time the zoom level or visible data range changes, the chart re-calculates the minimum point set.

Refer to the following topic for more information: Best Practices: Display Large Data

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.
            ResamplingDataAdapter dataAdapter = new ResamplingDataAdapter();

            // 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