DataSourceAdapter.DataMembers Property
Provides access to the collection of data members.
Namespace: DevExpress.WinUI.Charts
Assembly:
DevExpress.WinUI.Charts.v21.2.dll
Declaration
public DataMemberCollection DataMembers { get; }
Public ReadOnly Property DataMembers As DataMemberCollection
Property Value
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.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Charts="using:DevExpress.WinUI.Charts"
xmlns:local="using:BindChart"
x:Class="BindChart.MainWindow"
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>
</Window>
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;
}
}
}
using System;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
namespace BindChart {
public sealed partial class MainWindow : Page {
public MainWindow() {
this.InitializeComponent();
DataContext = new ViewModel() {
Start = 10000,
Count = 50000,
Step = TimeSpan.FromHours(3),
};
}
protected override void OnNavigatedTo(NavigationEventArgs e) {
}
}
}
Imports System
Imports Microsoft.UI.Xaml.Controls
Imports Microsoft.UI.Xaml.Navigation
Partial Public NotInheritable Class MainWindow
Inherits Page
Public Sub New()
Me.InitializeComponent()
DataContext = New ViewModel() With {.Start = 10000, .Count = 50000, .Increment = TimeSpan.FromHours(3)}
End Sub
Protected Overrides Sub OnNavigatedTo(ByVal e As NavigationEventArgs)
End Sub
End Class
Imports System
Imports System.Collections
Imports System.Collections.Generic
Public Class DateTimeDataPoint
Private privatePointArgument As DateTime
Private privatePointValue As Double
Public Property PointArgument() As DateTime
Get
Return privatePointArgument
End Get
Set(ByVal value As DateTime)
privatePointArgument = value
End Set
End Property
Public Property PointValue() As Double
Get
Return privatePointValue
End Get
Set(ByVal value As Double)
privatePointValue = value
End Set
End Property
End Class
Public Class ViewModel
Private startDate As New DateTime(2000, 1, 1)
Private ReadOnly random1 As New Random()
Private privateIncrement As TimeSpan
Public Property Increment() As TimeSpan
Get
Return privateIncrement
End Get
Set(ByVal value As TimeSpan)
privateIncrement = value
End Set
End Property
Private privateCount As Integer
Public Property Count() As Integer
Get
Return privateCount
End Get
Set(ByVal value As Integer)
privateCount = value
End Set
End Property
Private privateStart As Double
Public Property Start() As Double
Get
Return privateStart
End Get
Set(ByVal value As Double)
privateStart = value
End Set
End Property
Private privateItemsSource As IEnumerable
Public ReadOnly Property ItemsSource() As IEnumerable
Get
If privateItemsSource IsNot Nothing Then
Return privateItemsSource
Else
privateItemsSource = CreateItemsSource(Count)
Return privateItemsSource
End If
End Get
End Property
Protected Function CreateItemsSource(ByVal count As Integer) As IEnumerable
Dim points = New List(Of DateTimeDataPoint)()
Dim value As Double = GenerateStartValue(random1)
points.Add(New DateTimeDataPoint() With {.PointArgument = startDate, .PointValue = value})
For i As Integer = 1 To count - 1
value += GenerateAddition(random1)
startDate = startDate + Increment
points.Add(New DateTimeDataPoint() With {.PointArgument = startDate, .PointValue = value})
Next i
Return points
End Function
Protected Function GenerateStartValue(ByVal random As Random) As Double
Return Start + random.NextDouble() * 100
End Function
Protected Function GenerateAddition(ByVal random As Random) As Double
Dim factor As Double = random.NextDouble()
If factor = 1 Then
factor = 50
ElseIf factor = 0 Then
factor = -50
End If
Return (factor - 0.5) * 50
End Function
End Class
See Also