How to: Create Scorecard Transforms for PerformancePoint Services
In PerformancePoint Services in Microsoft SharePoint Server 2010, scorecard transforms change the appearance, content, or functionality of scorecard views before they render in a dashboard.
Applies to: SharePoint Server 2010
Note
We recommend that you use the scorecard transforms sample as a template for your custom transform. The sample shows how to call objects in the PerformancePoint Services API and demonstrates best practices for PerformancePoint Services development.
Creating Scorecard Transforms
The following procedure is based on the AddColumnTransform sample, which adds a column to scorecard views. The complete code for the class is provided in the first example in this topic.
To create a scorecard transform
Install PerformancePoint Services, or copy the DLLs that are installed with PerformancePoint Services to your computer. For more information, see PerformancePoint Services DLLs Used in Development Scenarios.
In Visual Studio, create a C# class library. If you have already created a class library for your extension, add a new C# class.
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 Overview of PerformancePoint Services Scorecard 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.
Example
Example 1: Adding a Column to Scorecard Views
The following code example is from the scorecard transforms sample. It 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.)
Note
Before you can compile this code example, you must configure your development environment as described in the "To create a scorecard transform" procedure.
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();
}
}
}
Example 2: Changing the Format of Empty Scorecard Cells
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 "To create a scorecard transform" procedure. 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;
}
}
}
}
}
Compiling the Code
Before you can compile these code examples, you must configure your development environment as described in the "To create a scorecard transform" procedure.
Security
You must sign your DLL with a strong name. In addition, ensure that all assemblies referenced by your DLL have strong names. For information about 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.
See Also
Concepts
Overview of PerformancePoint Services Scorecard Transforms
Other Resources
PerformancePoint Services Scorecards
How Do I... in PerformancePoint Services Development
Code Samples for PerformancePoint Services in SharePoint Server 2010