dashboard-devexpress-dot-dashboardcommon-9496bbea.md
An object data source that provides data for the dashboard.
Namespace : DevExpress.DashboardCommon
Assembly : DevExpress.Dashboard.v25.2.Core.dll
NuGet Package : DevExpress.Dashboard.Core
[DataAccessMetadata("All", SupportedProcessingModes = "Simple", EnableBindingToObjectDataSource = true, PreferAsyncDataLoading = false)]
public class DashboardObjectDataSource :
ObjectDataSource,
IDashboardDataSource,
IDashboardComponent,
IComponent,
IDisposable,
ISupportInitialize,
ISupportPrefix,
IDashboardDataSourceInternal,
IExternalSchemaConsumer,
IFederationDataProvider,
IFederationDataSchemaProvider
<DataAccessMetadata("All", SupportedProcessingModes:="Simple", EnableBindingToObjectDataSource:=True, PreferAsyncDataLoading:=False)>
Public Class DashboardObjectDataSource
Inherits ObjectDataSource
Implements IDashboardDataSource,
IDashboardComponent,
IComponent,
IDisposable,
ISupportInitialize,
ISupportPrefix,
IDashboardDataSourceInternal,
IExternalSchemaConsumer,
IFederationDataProvider,
IFederationDataSchemaProvider
To provide data for the DashboardObjectDataSource , assign the type of the required class to the DataSource property and set the DataMember property specifying the data member used to obtain the required data.
Handle the following events to supply the dashboard with actual data at runtime:
| Platform | Event |
|---|---|
| ASP.NET | ASPxDashboard.DataLoading, DashboardConfigurator.DataLoading |
| WinForms | DashboardDesigner.DataLoading, DashboardViewer.DataLoading |
| WinForms, in Async Mode | DashboardDesigner.AsyncDataLoading, DashboardViewer.AsyncDataLoading |
| WPF | DashboardControl.AsyncDataLoading |
| Any platform, not in Async Mode | Dashboard.DataLoading |
An object that provides data should implement the IEnumerable or IListSource interface.
Tip
You can create a custom fill service with the IObjectDataSourceCustomFillService interface, get access to the DashboardObjectDataSource configuration and use configuration parameters to modify the current data query.
The following example demonstrates how to bind a dashboard to a List object.
The quantity values are provided at runtime. The dashboard data source is added to the Dashboard.DataSources collection on the first load.
Click the Reload Data button to call the DashboardViewer.ReloadData method. It raises the DashboardViewer.DataLoading event and supplies the dashboard with updated data.
View Example: How to Bind a Dashboard to a List of Objects
using System;
using System.Collections.Generic;
using System.Threading;
namespace Dashboard_BindingToList {
public class Data {
public string SalesPerson { get; set; }
public int Quantity { get; set; }
public static List<Data> CreateData() {
List<Data> data = new List<Data>();
string[] salesPersons = { "Andrew Fuller", "Michael Suyama", "Robert King", "Nancy Davolio",
"Margaret Peacock", "Laura Callahan", "Steven Buchanan", "Janet Leverling" };
for (int i = 0; i < 100; i++) {
Data record = new Data();
int seed = (int)DateTime.Now.Ticks & 0x0000FFFF;
record.SalesPerson = salesPersons[new Random(seed).Next(0, salesPersons.Length)];
record.Quantity = new Random(seed).Next(0, 100);
data.Add(record);
Thread.Sleep(3);
}
return data;
}
}
}
using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
using DevExpress.DataAccess;
using DevExpress.XtraEditors;
using System;
namespace Dashboard_BindingToList {
public partial class Form1 : XtraForm {
public Form1() {
InitializeComponent();
dashboardViewer1.DataSourceOptions.ObjectDataSourceLoadingBehavior = DocumentLoadingBehavior.LoadAsIs;
dashboardViewer1.CustomizeDashboardTitle += DashboardViewer1_CustomizeDashboardTitle;
}
private void Form1_Load(object sender, System.EventArgs e) {
Dashboard dashboard = new Dashboard();
DashboardObjectDataSource dataSource = new DashboardObjectDataSource("Data Source 1");
dashboardViewer1.DataLoading += (s, ev) => {
if (ev.DataSourceName == "Data Source 1")
ev.Data = Data.CreateData();
};
dashboard.DataSources.Add(dataSource);
PieDashboardItem pies = new PieDashboardItem();
pies.DataSource = dashboard.DataSources[0];
Dimension salesPersonArgument = new Dimension("SalesPerson");
Measure quantity = new Measure("Quantity");
pies.Arguments.Add(salesPersonArgument);
salesPersonArgument.TopNOptions.Enabled = true; salesPersonArgument.TopNOptions.Count = 3;
salesPersonArgument.TopNOptions.Measure = quantity;
pies.Values.Add(quantity);
GridDashboardItem grid = new GridDashboardItem();
grid.DataSource = dashboard.DataSources[0];
grid.Columns.Add(new GridDimensionColumn(new Dimension("SalesPerson")));
grid.Columns.Add(new GridMeasureColumn(new Measure("Quantity")));
dashboard.Items.AddRange(pies, grid);
dashboardViewer1.Dashboard = dashboard;
}
private void DashboardViewer1_CustomizeDashboardTitle(object sender, CustomizeDashboardTitleEventArgs e)
{
DashboardToolbarItem titleButton = new DashboardToolbarItem("Load Data",
new Action<DashboardToolbarItemClickEventArgs>((args) =>
{
dashboardViewer1.ReloadData();
}));
titleButton.Caption = "Reload Data";
e.Items.Add(titleButton);
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Threading
Namespace Dashboard_BindingToList
Public Class Data
Public Property SalesPerson() As String
Public Property Quantity() As Integer
Public Shared Function CreateData() As List(Of Data)
'INSTANT VB NOTE: The variable data was renamed since it may cause conflicts with calls to static members of the user-defined type with this name:
Dim data_Renamed As New List(Of Data)()
Dim salesPersons() As String = { "Andrew Fuller", "Michael Suyama", "Robert King", "Nancy Davolio", "Margaret Peacock", "Laura Callahan", "Steven Buchanan", "Janet Leverling" }
For i As Integer = 0 To 99
Dim record As New Data()
Dim seed As Integer = CInt(Date.Now.Ticks And &HFFFF)
record.SalesPerson = salesPersons((New Random(seed)).Next(0, salesPersons.Length))
record.Quantity = (New Random(seed)).Next(0, 100)
data_Renamed.Add(record)
Thread.Sleep(3)
Next i
Return data_Renamed
End Function
End Class
End Namespace
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWin
Imports DevExpress.DataAccess
Imports DevExpress.XtraEditors
Imports System
Namespace Dashboard_BindingToList
Partial Public Class Form1
Inherits XtraForm
Public Sub New()
InitializeComponent()
dashboardViewer1.DataSourceOptions.ObjectDataSourceLoadingBehavior = DocumentLoadingBehavior.LoadAsIs
AddHandler dashboardViewer1.CustomizeDashboardTitle, AddressOf DashboardViewer1_CustomizeDashboardTitle
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dashboard As New Dashboard()
Dim dataSource As New DashboardObjectDataSource("Data Source 1")
AddHandler dashboardViewer1.DataLoading, Sub(s, ev)
If ev.DataSourceName = "Data Source 1" Then
ev.Data = Data.CreateData()
End If
End Sub
dashboard.DataSources.Add(dataSource)
Dim pies As New PieDashboardItem()
pies.DataSource = dashboard.DataSources(0)
Dim salesPersonArgument As New Dimension("SalesPerson")
Dim quantity As New Measure("Quantity")
pies.Arguments.Add(salesPersonArgument)
salesPersonArgument.TopNOptions.Enabled = True
salesPersonArgument.TopNOptions.Count = 3
salesPersonArgument.TopNOptions.Measure = quantity
pies.Values.Add(quantity)
Dim grid As New GridDashboardItem()
grid.DataSource = dashboard.DataSources(0)
grid.Columns.Add(New GridDimensionColumn(New Dimension("SalesPerson")))
grid.Columns.Add(New GridMeasureColumn(New Measure("Quantity")))
dashboard.Items.AddRange(pies, grid)
dashboardViewer1.Dashboard = dashboard
End Sub
Private Sub DashboardViewer1_CustomizeDashboardTitle(ByVal sender As Object, ByVal e As CustomizeDashboardTitleEventArgs)
Dim titleButton As DashboardToolbarItem = New DashboardToolbarItem("Load Data", New Action(Of DashboardToolbarItemClickEventArgs)(Sub(args)
dashboardViewer1.ReloadData()
End Sub))
titleButton.Caption = "Reload Data"
e.Items.Add(titleButton)
End Sub
End Class
End Namespace
Object MarshalByRefObject Component DataComponentBase ObjectDataSource DashboardObjectDataSource
See Also