Pages

Friday, September 16, 2016

SharePoint 2013: How to Connect a Filter to a Chart Web Part


Introduction

In this posting, I will walk you through the process of connecting a Choice Filter web part to a Chart web part so that the range of data shown in the chart depends on a user selection. The chart type will be a pie chart, and the filter type will be the Choice Filter web part. Interestingly, the Choice Filter web part won't be connected to a list that in turn is connected to a chart web part.  Instead, the filter will be connected directly to the chart web part itself.  This can be done because the chart web part has the capability to perform its own filtering on the datasets it consumes.  Furthermore, it can also consume filter values that it will then apply to the datasets it has consumed.  All of the steps for accomplishing this will be discussed here.  Note: these steps require that you have at least Design permission level to the page containing the web parts.

Background

The scenario that will be explored here involves enabling a user to select different sets of data associated with routine monthly SharePoint patching and then see the selected data set displayed in a pie chart. A set of data involves the aggregated times associated with eight patching tasks:
  1. Preparation
  2. Operating System Update Installation (OSU)
  3. SharePoint Update Installation (SPU)
  4. Run Get-SPProduct all SharePoint Servers (GSP)
  5. Run PSCONFIG all SharePoint Servers (PSC)
  6. OWA Update Installation and OWA Reconfiguration (OWA)
  7. Miscellaneous Tasks (Misc)
  8. Review and Regression Testing (Rev)
These are the general tasks performed every month for SharePoint farm patching.  The aggregate total times captured from such tasks are typically recorded to a list having a normalized transactional schema, where values are in minutes, as shown in Table 1 below.  These are the times associated with patching two SharePoint 2013 farms.  Each row represents a single dataset.
Table 1
Title Date Prep OSU SPU GSP PSC OWA Misc Rev Total Include
Patching: production 7/16/2016 0 192 105 139 195 6 0 60 11.52 Yes
Patching: Development 8/10/2016 30 117 124 188 38 9 0 64 9.35 Yes
Patching: Production 8/20/2016 37 144 133 31 35 16 0 36 6.93 Yes
Patching: Development 9/14/2016 10 131 127 120 95 7 0 55 8.97 Yes
The OSU aggregate is the total time involved with patching all farm Windows servers; SPU is the aggregated time associated with updating all farm SharePoint servers; Rev is the aggregated time associated with reviewing and regression testing; and so on. The times associated with these tasks are recorded for process monitoring and improvement purposes.  This sort of data listing follows the standard tabular format for related datasets (having a common X-value):
X-headerYA-HeaderYB-HeaderYC-Header
X1YA1YB1YC1
X2YA2YB2YC2
X3YA3YB3YC3
The data in Table 1 can be straightforwardly displayed in a chart object.  The Date column provides the X-value and the Prep, OSU, SPU, PSC, OWA, Misc and Rev columns provide the Y-values. Entering this data into a SharePoint list and connecting a chart object to this data results in a typical line chart.
This approach works fine for charting table data as lines. However, if you want display data in a pie chart, you have to reformat the data.  Pie charts do not display multiple datasets, but only one dataset at a time.  This means that a pie chart can only represent the Y-values of a dataset, and not the X value; in other words, a pie chart displays the values for a single row of Table 1.  The process for transposing data from a line chart to a pie chart runs like so:
  1. Choose a particular dataset (set of X,Y values)
  2. Remove the X-values, leaving the Y-values (YA1, YB1, YC1...)
  3. Identify the column headers and pair them with the Y-values
In other words, create a new table having just two columns and listing the values like so:
Item Value
YA-HeaderYA1
YB-HeaderYB1
YC-HeaderYC1
The first column does not represent X-values, but contains the column headers from Table 1.  These then become the pie chart labels for the pie slices.  The second displays the Y-values of the dataset.  These values are used to determine the relative sizes of the pie slices.  Therefore, if you wanted to display in a pie chart the task times for a patching session, you do it for one date at a time, building the list like so (Table 2):
Table 2
Task Duration
Prep0
OSU192
SPU105
GSP139
PSC195
OWA6
Misc0
Rev60
where this is the data for the patching session conducted on 7/16/2016, as shown in Table 1. To display multiple patching sessions in a pie chart, requires adding the data from these sessions to Table 2 and also adding some columns to it as well that enable the table to be filtered for a specific dataset.  The general process is:
  1. Add an additional column to the table that identifies the patching session for the dataset.  This is effectively the X-value for the dataset Y-values.  Call it the Session column, and it will be used to filter for a specific dataset.
  2. Add an additional filter column to identify whether a data item should be included in the chart.  This is useful when, perhaps, a particular update session only need to engage in some tasks or was a one-off that you don't want to include in your general process improvement data capture.
  3. Also add a column that provides additional explanation or definition of the task, calling it the Definition column.
  4. Lastly, reformat the Y-value headers to make them more readable and so that they can be conveniently sorted.
Making these modifications results in Table 3, below.
Table 3
Session Task Duration Include Definition
7/16/20161) Preparation0YesReview all updates
7/16/20162) OS Updates192YesInstall Operating System Updates
7/16/20163) SP Updates105YesInstall SharePoint Patches
7/16/20164) Get-SPProduct139YesRun Get-SPProduct
7/16/20165) PSCONFIG195YesRun PSCONFIG
7/16/20166) OWA Updates6YesInstall OWA updates
7/16/20167) Miscellaneous0YesMiscellaneous tasks
7/16/20168) Review60YesTesting and verification
8/10/20161) Preparation0YesReview all updates
8/10/20162) OS Updates192YesInstall Operating System Updates
8/10/20163) SP Updates105YesInstall SharePoint Patches
8/10/20164) Get-SPProduct139YesRun Get-SPProduct
8/10/20165) PSCONFIG195YesRun PSCONFIG
8/10/20166) OWA Updates6YesInstall OWA updates
8/10/20167) Miscellaneous0YesMiscellaneous tasks
8/10/20168) Review60YesTesting and verification
8/20/20161) Preparation0YesReview all updates
8/20/20162) OS Updates192YesInstall Operating System Updates
8/20/20163) SP Updates105YesInstall SharePoint Patches
8/20/20164) Get-SPProduct139YesRun Get-SPProduct
8/20/20165) PSCONFIG195YesRun PSCONFIG
8/20/20166) OWA Updates6YesInstall OWA updates
8/20/20167) Miscellaneous0YesMiscellaneous tasks
8/20/20168) Review60YesTesting and verification
9/14/20161) Preparation0YesReview all updates
9/14/20162) OS Updates192YesInstall Operating System Updates
9/14/20163) SP Updates105YesInstall SharePoint Patches
9/14/20164) Get-SPProduct139YesRun Get-SPProduct
9/14/20165) PSCONFIG195YesRun PSCONFIG
9/14/20166) OWA Updates6YesInstall OWA updates
9/14/20167) Miscellaneous0YesMiscellaneous tasks
9/14/20168) Review60YesTesting and verification
Note that the Session column lists the denormalized X-values associated with dataset Y-values.  By listing the X-values this way, this column can be used for filtering purposes.  By filtering for a specific date in this column, it's possible to extract a set of Y-values associated with a specific patching session.  In other words, if Table 3 is filtered by a particular date, one effectively gets back a table like Table 2.

In summary, this is the process you need to work through in order to get the data prepared. Once you have a list like Table 3 created, you're ready to configure a chart to use that data.  In the next section, you'll walk through the steps for accomplishing this.

Procedure

Step 1: Define Chart web part Filter Parameters
  1. Drop the Chart web part onto a page.
  2. Click Data & Appearance.
  3. Click Connect Chart to Data.
  4. Select Connect to a List, and then click the Next button.
  5. Select the website in the site collection containing the denormalized list, select the list, and then click the Next button. You'll now see your list displayed.
  6. Look up at the top of this list: do you see Filter Data? Click the arrow to expand it. This will reveal filters that you can define. Assuming that you have created a list having column names as shown in Table 3, configure the first parameter like so:
    1. Parameter Name: Session
    2. Type: DateTime
    3. Default value: 7/16/2016
  7. Now let's also implement the Include parameter. One thing: when you create this column, you selected the Yes/No type. Though it doesn't actually indicate this, it's implemented as a Boolean. When used in a list, and when you access the list in SharePoint, the value that you see for this column is Yes or No. But it is implemented as Boolean, but is not surfaced in that way. However, the Chart web part recognizes that column as in fact Boolean, and the values that it will show for that column are True and False. You don't need to change your list values, but you do need to account for this when specifying default or filter values.
    1. Parameter Name: Include
    2. Type: Boolean
    3. Default value: True
  8. Click the Preview Data button. This filters the list based upon the filter parameters you configured.
  9. Click the Next button. This page helps you configure a range of different chart aspects, including the data series' you want to present. For our needs, all you need to do is configure the Series Type, which should be Pie. Select that.
  10. Now click the Finish button. The pie chart will then be displayed. It needs some cleaning up, so let's do that next.
Step 2: Clean up the Pie Chart Display
  1. Click Advanced Properties. The first thing to do is configure a "collected slice," or a slice that contains other pie slices having less than some amount. Doing this helps clear up the clutter associated with having a number of very thin slices and their annotations all crammed together.
  2. From the Select an Element panel, select Series, and then scroll down to the bottom, to the Misc section. The configure as follows:
    1. CollectedThreshold: 10
    2. CollectedThresholdUsePercent: False
    3. CollectedThresholdExploded: True
    Like so:
  3. Now, from the Select an Element panel, select Chart (root element), and then scroll down to the bottom to the Image section. Then configure as follows:
    1. Height: 450
    2. Width: 650
  4. Now, from the Select an Element panel, select Series again, and then scroll down to the bottom, to the Misc section. The configure as follows:
    1. PieLabelStyle: Outside
    2. LabelsHorizontalLineSize: 0
  5. Staying on the Series element, scroll up until you see the MapArea section. Configure as follows (include the "#"):
    1. ToolTip: #VALY/#TOTAL (#PERCENT)
  6. This completes chart cleanup. You can certainly do far more here, but this is enough for our purposes. In the next step, you will add and configure a Choice Filter web part.
Step 3: Add and Configure a Choice Filter
  1. Put the page back in Edit mode.
  2. Drop a Choice Filter web part onto the page.
  3. Select Edit Web Part from the Choice Filter dropdown menu (hover the cursor over the web bar to see the dropdown appear).
  4. In the Filter section, enter a name for the filter and then enter a list of dates. These dates should be exactly the same as what you entered into the SharePoint list. Also enter a date that will be the default date.
    The default date is pushed into the Chart web part, when the page is instantiated and streamed to the user's browser. Having a default value ensures that the chart web part will display a chart when the user first connects to the page.
  5. Click OK. Now let's connect this filter web part to the chart web part.
Step 4: Connect the Choice Filter to the Chart
  1. Open the Choice Filter dropdown menu again, and then this time point to Connections, then point to Send Filter Values To, and then select the name of your chart web part.
    A dialog will appear. Note that the names of the parameters that appear in the dropdown on this dialog. Our Session parameter appears first.
  2. Select the Session parameter, and then click OK. Note the date that appears now in the Choice Filter web part.
    This is the default you entered previously.
  3. Click the small filter icon to the right of the Choice Filter web part. The Select Filter Value(s) dialog appears.
  4. Select another date, and then click OK. The dialog closes, and the page is refreshed, now displaying the data associated with that session date!
  5. At this point, you're set: you don't need any further significant configuration. The rest is customization.
  6. Here's a more cleaned up version:
    Note that to remove the toolbar, you'll need to edit the web page markup and set the Toolbar parameter of the Chart web part to False.  See the references for additional detail on this. Unfortunately, I don't know how to make the chart Title also update per the Choice filter - the Title text doesn't accept keywords.  If you know of a simple way, add your comment!  For additional hints and guidance on customization, see 

References

  • If you should subsequently edit the Choice Filter web part again - maybe changing its title or some such - don't be surprised that this seems to break the connection between this web part and the Chart web part.  I find this occurs almost every time.  Even if I'm in SharePoint Designer and make a single change to a parameter (e.g., changing True to False), and carefully save the file so that nothing else is changed - even this causes the connection to break.  The fix is simple: just rebuild the connection in the usual way.
  • You can also implement a similar capability using the List Filter instead.  This takes a list of values from a column in a SharePoint list that you specify.  This approach enables you to update the filter parameter list by just editing a list rather than having to edit a web page (which requires Design level permission).

No comments:

Post a Comment