Providing Data
- 4 minutes to read
The Dashboard Designer allows you to bind various dashboard items to data in a virtually uniform manner. To learn more, see the Binding Dashboard Items to Data topic.
The only difference is in the data sections that the required dashboard item has. This topic describes how to bind a Pivot dashboard item to data in the Designer or in code.
Binding to Data in the Designer
The image below shows a sample Pivot dashboard item that is bound to data.
To bind the Pivot dashboard item to data, drag and drop a data source field to a placeholder contained in one of the available data sections. A table below lists and describes a Pivot’s data sections.
Section | Processed as | Description |
---|---|---|
Values | Measure | Contains data items used to calculate values displayed in the pivot table. |
Columns | Dimension | Contains data items whose values are used to label columns. |
Rows | Dimension | Contains data items whose values are used to label rows. |
Transposing Columns and Rows
The Pivot dashboard item provides the capability to transpose pivot columns and rows. In this case, data items contained in the Columns section are moved to the Rows section and vice versa.
To transpose the selected Pivot dashboard item, use the Transpose button in the Home ribbon tab.
Binding to Data in Code
To provide data for the Pivot dashboard item, use the following properties.
Values | |
Columns | |
Rows |
Example
The following example demonstrates how to bind a Pivot dashboard item to data in code.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-bind-a-pivot-dashboard-item-to-data-in-code-e4772.
using System;
using System.Windows.Forms;
using DevExpress.DashboardCommon;
using DevExpress.DataAccess;
namespace Dashboard_CreatePivot {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private PivotDashboardItem CreatePivot(DashboardObjectDataSource dataSource) {
// Creates a pivot dashboard item and specifies its data source.
PivotDashboardItem pivot = new PivotDashboardItem();
pivot.DataSource = dataSource;
// Specifies dimensions that provide pivot column and row headers.
pivot.Columns.AddRange(new Dimension("Country"), new Dimension("Sales Person"));
pivot.Rows.AddRange(new Dimension("CategoryName"), new Dimension("ProductName"));
// Specifies measures whose data is used to calculate pivot cell values.
pivot.Values.AddRange(new Measure("Extended Price"), new Measure("Quantity"));
// Specifies the default expanded state of pivot column field values.
pivot.AutoExpandColumnGroups = true;
return pivot;
}
private void Form1_Load(object sender, EventArgs e) {
// Creates a dashboard and sets it as the currently opened dashboad in the dashboard viewer.
dashboardViewer1.Dashboard = new Dashboard();
// Creates a data source and adds it to the dashboard data source collection.
DashboardObjectDataSource dataSource = new DashboardObjectDataSource();
dataSource.DataSource = (new nwindDataSetTableAdapters.SalesPersonTableAdapter()).GetData();
dashboardViewer1.Dashboard.DataSources.Add(dataSource);
// Creates a pivot dashboard item with the specified data source
// and adds it to the Items collection, to display it within the dashboard.
PivotDashboardItem pivot = CreatePivot(dataSource);
dashboardViewer1.Dashboard.Items.Add(pivot);
// Reloads data in the data sources.
dashboardViewer1.ReloadData();
}
}
}