FlexPivot for WinForms
OLAPでKPIの表示
FlexPivot キューブ > OLAPでKPIの表示

An OLAP (On-line Analytical Processing) Cube is a multi-dimensional database that performs instantaneous analysis and display of large chunks of data. The cube contains metrics of data such as KPI (Key Performance Indicator) information, which can be used to measure the progress of a business in meeting its goals. Being an excellent data processing tool, the FlexPivot control can automatically recognize the information in the OLAP Cube and display it in an appropriate format in its page.

The GIF below displays a report on the FlexPivotPage for the Internet Revenue/Sales KPI from the Adventure Works sample cube. Note how the KPI data is shown in the FlexPivotPage using the Value Fields.

For each KPI in the OLAP cube, there is a corresponding measure for its status and trend. The associated graphics of each KPI can be specified using the KpiGraphics enumeration of the C1.FlexPivot.Internal namespace. In the code below, a Combo Box is used to display the KpiGraphics enumeration values to alter the KPI graphics at runtime. The selected graphics can be applied to the KPI fields using the C1KpiField class of C1.FlexPivot.Internal namespace.

The code below illustrates how to add KPI Field data from OLAP Cube in the FlexPivotPage.

Partial Public Class Form1
    Inherits Form

    Private flexPivotPage1 As FlexPivotPage
    Private KpiGraphicsCombo As ComboBox

    Public Sub New()
        InitializeComponent()
        flexPivotPage1 = New FlexPivotPage()
        flexPivotPage1.Height = 500
        flexPivotPage1.Width = 800
        flexPivotPage1.Dock = DockStyle.Bottom
        Dim connectionString As String = "Data Source=http://ssrs.componentone.com/OLAP/msmdpump.dll;Provider=msolap;Initial Catalog=AdventureWorksDW2012Multidimensional"
        Dim cubeName As String = "Adventure Works"
        flexPivotPage1.FlexPivotPanel.ConnectCube(cubeName, connectionString)
        Dim fp = flexPivotPage1.PivotEngine
        fp.BeginUpdate()
        fp.ColumnFields.Add("Date.Fiscal Year")
        fp.RowFields.Add("Category")
        fp.ValueFields.Add("Internet Revenue Trend")
        fp.ValueFields.Add("Internet Revenue Status")
        fp.EndUpdate()
        Me.Controls.Add(flexPivotPage1)
        KpiGraphicsCombo = New ComboBox()
        KpiGraphicsCombo.Left = 160
        KpiGraphicsCombo.Top = 35
        KpiGraphicsCombo.DataSource = [Enum].GetValues(GetType(C1.PivotEngine.Internal.KpiGraphics))
        KpiGraphicsCombo.SelectedIndexChanged += AddressOf KpiGraphicsComboBox_SelectedIndexChanged
        Me.Controls.Add(KpiGraphicsCombo)
    End Sub

    Private Sub KpiGraphicsComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        Scan(flexPivotPage1.PivotEngine.Fields)
    End Sub

    Private Sub Scan(ByVal list As IEnumerable(Of PivotField))
        For Each field In list
            If TypeOf field Is KpiField Then (TryCast(field, KpiField)).KpiGraphics = CType([Enum].Parse(GetType(C1.PivotEngine.Internal.KpiGraphics), KpiGraphicsCombo.SelectedValue.ToString()), C1.PivotEngine.Internal.KpiGraphics)
            If TypeOf field Is CubeField Then Scan((TryCast(field, CubeField)).SubFields)
        Next
    End Sub
End Class
public Form1()
{
    InitializeComponent();

    //Initialize FlexPivotPage
    flexPivotPage1 = new FlexPivotPage();
    flexPivotPage1.Height = 500;
    flexPivotPage1.Width = 800;
    flexPivotPage1.Dock = DockStyle.Bottom;

    //Set up connection string
    string connectionString = @"Data Source=http://ssrs.componentone.com/OLAP/msmdpump.dll;Provider=msolap;Initial Catalog=AdventureWorksDW2012Multidimensional";
    string cubeName = "Adventure Works";
    //Connect Cube Data to FlexPivotPage
    flexPivotPage1.FlexPivotPanel.ConnectCube(cubeName, connectionString);

    //Show KPI Field data in the FlexPivotPage using ValueFields
    var fp = flexPivotPage1.PivotEngine;
    fp.BeginUpdate();
    fp.ColumnFields.Add("Date.Fiscal Year");
    fp.RowFields.Add("Category");
    fp.ValueFields.Add("Internet Revenue Trend");
    fp.ValueFields.Add("Internet Revenue Status");
    fp.EndUpdate();

    //Add FlexPivotPage to form
    this.Controls.Add(flexPivotPage1);

    //Intialize KPI Graphics ComboBox
    KpiGraphicsCombo = new ComboBox();
    KpiGraphicsCombo.Left = 160;
    KpiGraphicsCombo.Top = 35;

    //Populate Combobox with KpiGraphics enum values to alter graphic at runtime
    KpiGraphicsCombo.DataSource = Enum.GetValues(typeof(C1.PivotEngine.Internal.KpiGraphics));
    KpiGraphicsCombo.SelectedIndexChanged += KpiGraphicsComboBox_SelectedIndexChanged;

    //Add ComboBox to form
    this.Controls.Add(KpiGraphicsCombo);
}

//Invoke the method to apply the selected KPI graphics
private void KpiGraphicsComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    Scan(flexPivotPage1.PivotEngine.Fields);
}

//Apply the selected graphics to KPI fields
void Scan(IEnumerable<PivotField> list)
{
    foreach (var field in list)
    {
        if (field is KpiField)
            (field as KpiField).KpiGraphics = (C1.PivotEngine.Internal.KpiGraphics)Enum.Parse(typeof(C1.PivotEngine.Internal.KpiGraphics), KpiGraphicsCombo.SelectedValue.ToString());
        if (field is CubeField)
            Scan((field as CubeField).SubFields);
    }
}