Skip to main content

DataSourceAdapter.DataMembers Property

Provides access to the collection of data members.

Namespace: DevExpress.UI.Xaml.Charts

Assembly: DevExpress.UI.Xaml.Charts.v21.2.dll

NuGet Package: DevExpress.Uwp.Controls

Declaration

public DataMemberCollection DataMembers { get; }

Property Value

Type Description
DataMemberCollection

A DataMemberCollection object.

Remarks

For more information, refer to Providing Data.

Example

The following example demonstrates how to bind a chart to data provided by a ViewModel.

To do this, it is necessary to assign the DataSourceAdapter object to the Series.Data property and specify the datasource for the adapter via its DataSourceAdapter.DataSource property.

<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BindChart"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Charts="using:DevExpress.UI.Xaml.Charts"
    x:Class="BindChart.MainPage"
    mc:Ignorable="d">

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">

        <Charts:CartesianChart>
            <Charts:Series>
                <Charts:Series.View>
                    <Charts:LineSeriesView/>
                </Charts:Series.View>
                <Charts:Series.Data>
                    <Charts:DataSourceAdapter DataSource="{Binding ItemsSource}">
                        <Charts:DataMember DataMemberType="Argument" ColumnName="PointArgument" 
                                           ScaleType="DateTime"/>
                        <Charts:DataMember DataMemberType="Value" ColumnName="PointValue" 
                                           ScaleType="Auto"/>
                    </Charts:DataSourceAdapter>
                </Charts:Series.Data>
            </Charts:Series>
            <Charts:CartesianChart.AxisX>
                <Charts:AxisX DateTimeGridAlignment="Year" DateTimeMeasureUnit="Hour">
                    <Charts:AxisX.LabelOptions>
                        <Charts:AxisLabelOptions Pattern="{}{V:yyyy}"/>
                    </Charts:AxisX.LabelOptions>
                </Charts:AxisX>
            </Charts:CartesianChart.AxisX>
        </Charts:CartesianChart>

    </Grid>
</Page>
using System;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace BindChart {

    public sealed partial class MainPage : Page {

        public MainPage() {
            this.InitializeComponent();
            DataContext = new ViewModel() {
                Start = 10000,
                Count = 50000,
                Step = TimeSpan.FromHours(3),
            };
        }

        protected override void OnNavigatedTo(NavigationEventArgs e) {
        }
    }
}
using System;
using System.Collections;
using System.Collections.Generic;

namespace BindChart {

    public class DateTimeDataPoint {
        public DateTime PointArgument { get; set; }
        public double PointValue { get; set; }
    }

    public class ViewModel {
        DateTime start = new DateTime(2000, 1, 1);
        IEnumerable itemsSource;
        readonly Random random = new Random();


        public TimeSpan Step { get; set; }
        public int Count { get; set; }
        public double Start { get; set; }
        public IEnumerable ItemsSource { 
            get { return itemsSource ?? (itemsSource = CreateItemsSource(Count)); } 
        }

        protected IEnumerable CreateItemsSource(int count) {
            var points = new List<DateTimeDataPoint>();

            double value = GenerateStartValue(random);
            points.Add(new DateTimeDataPoint() { PointArgument = start, PointValue = value });
            for (int i = 1; i < count; i++) {
                value += GenerateAddition(random);
                start = start + Step;
                points.Add(new DateTimeDataPoint() { PointArgument = start, PointValue = value });
            }
            return points;
        }

        protected double GenerateStartValue(Random random) {
            return Start + random.NextDouble() * 100;
        }

        protected double GenerateAddition(Random random) {
            double factor = random.NextDouble();
            if (factor == 1)
                factor = 50;
            else if (factor == 0)
                factor = -50;
            return (factor - 0.5) * 50;
        }
    }
}
See Also