Create scorecard transforms for PerformancePoint Services in SharePoint
Learn how to create custom scorecard transforms for PerformancePoint Services in SharePoint.
What are scorecard transforms in PerformancePoint Services?
In PerformancePoint Services, scorecard transforms change the appearance, content, or functionality of scorecard views before they render in a dashboard. For more information, see Types of Transforms.
Create transforms for PerformancePoint Services scorecards
Install PerformancePoint Services, or copy the DLLs that are installed with PerformancePoint Services to your computer. For more information, see DLLs with Class Libraries.
In Visual Studio, create a C# class library. If you have already created a class library for your extension, add a new C# class.
You must sign your DLL with a strong name, and ensure that all assemblies referenced by your DLL have strong names. To learn how to sign an assembly with a strong name and how to create a public/private key pair, see How to: Create a Public/Private Key Pair.
Add Microsoft.PerformancePoint.Scorecards.Client.dll as an assembly reference to the project.
Add using directives for the following namespaces:
Microsoft.PerformancePoint.Scorecards
Microsoft.PerformancePoint.Scorecards.Extensions
System.Collections.Generic
Implement the IGridViewTransform interface.
Override the GetId method to return the string identifier for your transform. GetId must return the same string as the key attribute that is registered for the transform in the PerformancePoint Services web.config file. For more information about registering scorecard transforms, see How to: Manually Register PerformancePoint Services Extensions.
Override the GetTransformType method to specify when to run the transform. The point at which a transform runs depends on its type, as defined by the GridViewTransformType enumeration: PreQuery, PostQuery, or PreRender. For more information, see Types of Transforms.
Override the Execute method to define how to transform the scorecard. The following code examples show how to add a column to a scorecard view and how to change the formatting of empty scorecard cells.
After you sign and build your DLL, install the extension as described in How to: Manually Register PerformancePoint Services Extensions.
Code example 1: Add a column to PerformancePoint Services scorecards
The following code example creates a PreQuery transform that adds a column to rendered scorecard views that contain a KPI at the column leaf level. (If the scorecard view includes members below the KPIs, the column is not added.)
Before you can compile this code example, you must configure your development environment as described in Create transforms for PerformancePoint Services scorecards.
using System;
using System.Collections.Generic;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.Extensions;
namespace Microsoft.PerformancePoint.SDK.Samples.ScorecardTransforms.PreQuery
{
// Represents the class that adds columns of data to a scorecard view.
public class AddColumnTransform : IGridViewTransform
{
// Set transform type to PreQuery.
public GridViewTransformType GetTransformType()
{
return GridViewTransformType.PreQuery;
}
// Return the string identifier of your transform. This value must
// match the key attribute registered in the web.config file.
public string GetId()
{
return "AddColumn";
}
// Run the transform to add a column.
public void Execute(GridViewData viewData, PropertyBag parameters, IGlobalCache cache)
{
// Verify the scorecard definition.
if (viewData == null)
{
throw new ArgumentException("Parameter cannot be null", "viewData");
}
List<GridHeaderItem> leafRowHeaders = viewData.RootRowHeader.GetAllLeafHeadersInTree();
foreach (GridHeaderItem rowHeader in leafRowHeaders)
{
if (rowHeader.HeaderType == ScorecardNodeTypes.Kpi)
{
Kpi kpi = cache.GetKpi(rowHeader.LinkedKpiLocation);
if (kpi != null && viewData.RootColumnHeader != null)
{
// Create the column header and add it to the root.
GridHeaderItem theNewColumn = GridHeaderItem.CreateDetailsHeader(kpi.Owner.DisplayName);
// Set the GUIDs for the data headers.
// Setting the DefinitionGuid property to the
// same value as the root column header enables
// Dashboard Designer to display the scorecard.
// Note: Do not try to modify or delete the new
// column from within Dashboard Designer.
theNewColumn.DefinitionGuid = viewData.RootColumnHeader.DefinitionGuid;
theNewColumn.Parent = viewData.RootColumnHeader;
theNewColumn.Guid = new Guid();
// Insert the column at the end of the collection
// of child elements.
if (viewData.RootColumnHeader.Children.Count != 0)
{
viewData.RootColumnHeader.Children.Insert(viewData.RootColumnHeader.Children.Count, theNewColumn);
}
break;
}
}
}
viewData.RootColumnHeader.LinkAndIndexTreeFromRoot();
}
}
}
Code example 2: Change the format of empty cells in PerformancePoint Services scorecards
The following code example creates a PreQuery transform that applies a grey background color to empty scorecard cells.
Note
Before you can compile this code example, you must configure your development environment as described in Create transforms for PerformancePoint Services scorecards. In addition, you must add a reference to the System.Drawing assembly to your project.
using System;
using System.Collections.Generic;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.Extensions;
namespace Microsoft.PerformancePoint.SDK.Samples
{
// Represents a transform that applies a grey background color to empty scorecard cells.
public class GreyEmptiesTransform : IGridViewTransform
{
// Set the transform type to "PreRender".
public GridViewTransformType GetTransformType()
{
return GridViewTransformType.PreRender;
}
// Return the string identifier of the transform.
public string GetId()
{
return "GreyEmptyCells";
}
// Run the transform.
public void Execute(GridViewData viewData, PropertyBag parameters, IGlobalCache cache)
{
// Validate parameters.
if (viewData == null)
{
throw new ArgumentException("Parameter cannot be null", "viewData");
}
// Get the headers under the root row header.
List<GridHeaderItem> nonLeafRowHeaders = viewData.RootRowHeader.GetAllHeadersInTree();
// Get the leaf headers under the root column header.
List<GridHeaderItem> leafColumnHeaders = viewData.RootColumnHeader.GetAllLeafHeadersInTree();
foreach (GridHeaderItem rowHeader in nonLeafRowHeaders)
{
foreach (GridHeaderItem columnHeader in leafColumnHeaders)
{
// Get scorecard cells.
GridCell cell = viewData.Cells[rowHeader, columnHeader];
if (cell.IsCellEmpty || string.IsNullOrEmpty(cell.ActualValue.ToString()))
{
GridFormatInfo emptyFormat = new GridFormatInfo(viewData.DefaultCellFormatInfo);
emptyFormat.BackColor = new GridColor(System.Drawing.Color.Gray);
cell.FormatInfo = emptyFormat;
}
viewData.Cells[rowHeader, columnHeader] = cell;
}
}
}
}
}