dashboard-15456-winforms-dashboard-winforms-designer-create-dashboards-in-the-winforms-designer-dashboard-item-settings-pivot-providing-data.md
The Dashboard Designer allows you to bind dashboard items to data in a uniform and similar manner. See the Bind Dashboard Items to Data topic for common information.
The difference is in the data sections that the specific dashboard item has. This topic describes how to bind the Pivot dashboard item to data in the Designer or in code.
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. |
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.
To provide data for the Pivot dashboard item, use the following properties.
|
Values
|
| |
Columns
|
| |
Rows
|
|
The following example demonstrates how to bind a Pivot dashboard item to data in code.
using System;
using System.Windows.Forms;
using DevExpress.DashboardCommon;
namespace Dashboard_CreatePivot {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private PivotDashboardItem CreatePivot(IDashboardDataSource dataSource) {
PivotDashboardItem pivot = new PivotDashboardItem();
pivot.DataSource = dataSource;
pivot.Columns.AddRange(new Dimension("Country"), new Dimension("Sales Person"));
pivot.Rows.AddRange(new Dimension("CategoryName"), new Dimension("ProductName"));
pivot.Values.AddRange(new Measure("Extended Price"), new Measure("Quantity"));
pivot.AutoExpandColumnGroups = false;
pivot.AutoExpandRowGroups = true;
return pivot;
}
private void Form1_Load(object sender, EventArgs e) {
Dashboard dashboard = new Dashboard();
DashboardExcelDataSource dataSource = new DashboardExcelDataSource()
{
FileName = "SalesPerson.xlsx",
SourceOptions = new DevExpress.DataAccess.Excel.ExcelSourceOptions(
new DevExpress.DataAccess.Excel.ExcelWorksheetSettings()
{
WorksheetName = "Data",
CellRange = "A1:L100"
}
)
};
dataSource.Fill();
dashboard.DataSources.Add(dataSource);
PivotDashboardItem pivot = CreatePivot(dataSource);
dashboard.Items.Add(pivot);
dashboardViewer1.Dashboard = dashboard;
dashboardViewer1.ReloadData();
}
}
}
Imports System
Imports System.Windows.Forms
Imports DevExpress.DashboardCommon
Namespace Dashboard_CreatePivot
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Function CreatePivot(ByVal dataSource As IDashboardDataSource) As PivotDashboardItem
Dim pivot As New PivotDashboardItem()
pivot.DataSource = dataSource
pivot.Columns.AddRange(New Dimension("Country"), New Dimension("Sales Person"))
pivot.Rows.AddRange(New Dimension("CategoryName"), New Dimension("ProductName"))
pivot.Values.AddRange(New Measure("Extended Price"), New Measure("Quantity"))
pivot.AutoExpandColumnGroups = False
pivot.AutoExpandRowGroups = True
Return pivot
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim dashboard As New Dashboard()
Dim dataSource As New DashboardExcelDataSource() With {.FileName = "SalesPerson.xlsx", .SourceOptions = New DevExpress.DataAccess.Excel.ExcelSourceOptions(New DevExpress.DataAccess.Excel.ExcelWorksheetSettings() With {.WorksheetName = "Data", .CellRange = "A1:L100"})}
dataSource.Fill()
dashboard.DataSources.Add(dataSource)
Dim pivot As PivotDashboardItem = CreatePivot(dataSource)
dashboard.Items.Add(pivot)
dashboardViewer1.Dashboard = dashboard
dashboardViewer1.ReloadData()
End Sub
End Class
End Namespace