Chapter 26. Advanced Reporting Services Charting

In the last chapter, we introduced the fundamentals of SQL Server Reporting Services. Reporting Services allow you to quickly create visually appealing charts or formatted reports for print or export to other formats. We also explored the ability to produce OData feeds and discussed the use cases for doing so.

In this chapter, we develop some more advanced skills by building on the basic reporting we did in Chapter 25. We will first develop a basic drill-down report that allows us to drill through the members of our chart. We will then move on to a more advanced technique using JavaScript to spawn a new window with the drill-down report.

The second technique, while more complicated, is worth noting because it enables you to drill down to anything that supports a URL. You could drill into another report as we’ll show here, or into any web application. It’s not a technique that’s been broadly used, but it is very useful.

The mechanics of what we’re doing are pretty simple. We have an existing report that we’re going to enhance with a click-through action. When you click on a product line in the report, you will pass that selected product line as a parameter to a second report.

The first thing you need to do is create that second report. It’s no different than your first report other than accepting a parameter for a product line by which you will filter your data. Let’s do it!

Create a Drill-Down Report

Start by selecting the All Documents view from the Library ribbon. Then choose to create a new Report Builder report, which will be our drill-down report. See Figure 26-1.

Adding a Report Builder report
Figure 26-1. Adding a Report Builder report

Creating a Basic Chart

From the New Report, menu, create a new chart report using the Chart wizard as shown in Figure 26-2.

Launching the Chart wizard
Figure 26-2. Launching the Chart wizard

As you walk through the familiar process of creating your report, you could make a new dataset if that was appropriate for your solution. Another technique that’s worth highlighting is the ability to reuse your existing shared dataset from Chapter 25 and implement a dataset filter for your product line parameter.

  1. Within the New Chart wizard, let’s choose an existing dataset.

  2. Browse to find and reuse the same data set from your earlier example (see Figure 26-3).

Selecting existing dataset
Figure 26-3. Selecting existing dataset

Now, repeat the process of creating your visualization in the Chart wizard, as shown in Figure 26-4. This time you should create a pie chart. The goal of this new report is to show the ticket counts by product for a specified product line.

Creating a pie chart
Figure 26-4. Creating a pie chart

This time, add Product to the Categories and the Sum(Distinct Ticket Count) to your Values. You’ll notice that, depending on the chart type, the wizard will present the appropriate fields for data binding as shown in Figure 26-5. You can also revisit your selections later by editing the chart’s properties, but the wizard is the faster way to get going.

Arranging chart fields
Figure 26-5. Arranging chart fields

Applying Predefined Styles

Choose your style again as shown in Figure 26-6. These styles are a great way to get started with consistent formatting on your reports. You can customize the look and feel later using the design tools.

Choosing a chart style
Figure 26-6. Choosing a chart style

Note

If you find that you want to add additional styles or customize a style, these are all defined in a text file called StyleTemplates.xml. This will exist both on your local Visual Studio install and on the report server.

The path may vary in your installation, but will be similar to this:

C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEPrivateAssembliesBusiness Intelligence WizardsReportsStyles StyleTemplates.xml

Size the Chart and Preview

Continuing with your drill-down report, resize the pie chart to fit the full width and run it. Notice that all products are shown regardless of product line, as in Figure 26-7. You’ll need to apply a filter next to limit the results to a single product line.

Previewing the unfiltered pie chart
Figure 26-7. Previewing the unfiltered pie chart

Adding a Parameter to the Report

Return to design mode by clicking the Design button on the ribbon. Next, add a parameter to the report by right-clicking on Parameters in the Report Data pane, and choose Add Parameter from the context menu.

You now need to choose a name for the parameter. This will be the name you’ll use on the URL query string when you pass along the value. Next, choose a display prompt, which is the visual display name if a value is manually entered, and then select the appropriate data type, in this case text and, finally, allow blank values. The completed parameter dialog is shown in Figure 26-8.

Adding a ProductLine report parameter
Figure 26-8. Adding a ProductLine report parameter

Applying Dataset Filters

To limit the results of your query, apply a filter to your dataset that restricts the data to only data where the product line matches the parameter passed to our report.

  1. Within the Report Data pane on the left, expand the datasets node, right-click on your data set and launch the Dataset Properties dialog.

  2. Select the Filters tab, as shown in Figure 26-9.

  3. Add a new Filter.

  4. Choose ProductLine as the expression to filter.

  5. Choose Like as the operator.

  6. Launch the formula builder to define our constraint.

You may wonder why we’ve told you to select Like instead of Equals as your operator. When filtering data from a cube, it’s important to remember that your dimensions are all defined as hierarchies. Therefore, the table name is included as a part of the hierarchy. A good example of this is [Queues][Bikes], where you will be passing online bikes as your product line. For this reason, you’ll want to use a Like operator and apply wildcards in your filter.

Configuring a dataset filter
Figure 26-9. Configuring a dataset filter

Note

It’s also worth considering that your dataset dates will be returned as text. If you’d like to filter your data for everything before or after a set of dates, you will need to use the formula builder to cast your selected column as a date using the CDATE(ColumnName) syntax.

Construct a Filter Expression

Filter expressions are pretty easy once you understand the basic syntax. The * acts as a wildcard character matching anything before or anything after the parameter that we pass in. The % acts as a single character wildcard.

="*" + Parameters!ProductLine.Value + "*"

For example, %o%th* would allow words such as North or South with anything following them to match.

Note

You can find more information on the MSDN website.

Let’s use the expression builder as shown in Figure 26-10 to walk through building your filter. All the fields of your dataset, parameters, and common functions are available in the Category pane of the dialog.

Dataset filter expression editor
Figure 26-10. Dataset filter expression editor

Validating the Parameterized Report

When you run the report, you will be prompted to enter a product line. Enter a valid example such as Bikes and a pie chart of Bikes will return.

Previewing with a filter parameter
Figure 26-11. Previewing with a filter parameter

Jumping back into design mode, let’s clean up the chart. Right-click on the chart and select Show Data Labels as in Figure 26-12. From here, you can change many of the properties of your chart.

Formatting the chart with context menu properties
Figure 26-12. Formatting the chart with context menu properties

To complete the cleanup, click on the data labels to select them. You can bold them and format them as white to make them stand out a bit. If you like, you can change the fonts as we’ve used Segoe UI Light for a look that is more consistent with the Windows 8 user interface.

Creating a Dynamic Chart Title

When creating a parameter driven report, you should provide your users with a chart title that clearly articulates the data they are looking at. Reporting Services has a default text-based title at the top of each report. Your chart also has a title on it, which may be redundant.

  1. Select the chart title and delete it to give the pie chart some more space.

  2. Select the chart on the page and turn off borders from the ribbon for a cleaner look.

  3. Right-click on the report title and build an expression for our value:

    ="Tickets by Product for " + Parameters!ProductLine.Value

You could add some text such as “Tickets by Product” with the ProductLine parameter to provide some context on your drill-down report to let people know what they are looking at. This is shown in Figure 26-13.

Creating a dynamic chart title with the expression editor
Figure 26-13. Creating a dynamic chart title with the expression editor

Headers and Footers

For this solution, let’s remove the page footer by right-clicking on the bottom of the report and choosing Remove Page Footer, as shown in Figure 26-14.

For some use cases, it may make sense to append copyright, usage guidelines, or the time that the report was executed in this area. The report headers and footers will be automatically added on each page of your report if you have a multipage report.

Removing chart footer
Figure 26-14. Removing chart footer

The completed drill-down report is shown in Figure 26-15. Now, save it to your library as a product drill-down and then proceed to wire it up to the summary report you created in Chapter 25.

Completed drill-down report
Figure 26-15. Completed drill-down report

Figure 26-16 shows both reports saved to a SharePoint library. Next, let’s connect these reports to allow for click-through from your Tickets By Product Line report.

SharePoint library with both reports
Figure 26-16. SharePoint library with both reports

Two Approaches to Drill-Down Reporting

Out of the box, SQL Server Reporting Services supports the ability to have basic drill-down reports. When you click on a hyperlink or an area of a chart, you can pass along a parameter and drill down to another report. The client’s browser will redirect to the new report, leaving the context of the top-level report.

While the simple drill-down has great functionality and is fairly easy to implement, sometimes you’ll want to keep the context of the original report and spawn a new window for the drill-down details. A second approach will use some JavaScript to spawn a dialog for a drill-down report and could be used to open any URL while maintaining the context of the original report.

Basic Drill-Down Reports

  1. Start with our Tickets By Product Line report.

  2. Display the library via the All Documents View from the ribbon.

  3. Activate the Edit Control Block on your basic report.

  4. Choose Edit in Report Builder to launch Report Builder 3.0, as shown in Figure 26-17.

    Editing an existing report in Report Builder
    Figure 26-17. Editing an existing report in Report Builder

Your original report should now display in the Report Builder editor. Right-click on the chart series and activate the Series Properties dialog, as shown in Figure 26-18.

Series Properties dialog in Report Builder
Figure 26-18. Series Properties dialog in Report Builder

In the Series Properties dialog, select the Action tab, as shown in Figure 26-19. Actions allow you to define what happens when a user clicks on a member of this series in the report at render time.

  1. Select Go to report.

  2. Browse for the path to the drill-down report using the browse button.

  3. Add a new parameter.

  4. Select the name of the parameter (ProductLine in this case).

  5. Activate the drop-down menu to select the value from the items in your current dataset, again ProductLine. This automatically wires your report to pass along the product line value from your series when a user clicks on a member of the chart series.

Linking to a drill-down report in the Action tab of the Series Properties dialog
Figure 26-19. Linking to a drill-down report in the Action tab of the Series Properties dialog

Now, run the report and try it out. You’ll notice that your mouse cursor now indicates a link when you hover over a chart element, even inside the Report Builder preview shown in Figure 26-20.

Previewing basic drill-down
Figure 26-20. Previewing basic drill-down

When you click on a chart element, you will drill down, automatically replacing the original report. Don’t forget to save your changes. All this will work the same way via SharePoint.

Drill-down report
Figure 26-21. Drill-down report

Advanced Pop-Up Window Drill-Down Report

In this example, we’ll build on the previous drill-down, but will leverage JavaScript and the URL parameter support of Reporting Services Integrated Mode to keep your users in context by providing a drill-down report as a pop-up.

  1. Start in the All Document View of your PowerPivot library.

  2. Edit your main report by launching Report Builder from the Edit Control Block.

  3. Once again, right-click on the chart series to access the Series Properties.

  4. Select the Action tab again, as shown in Figure 26-22.

  5. Instead of selecting Go to report as the action, change it to Go to URL.

  6. Launch the formula builder to create a URL.

  7. Enter the expression in your code example and click OK. Don’t worry; we’ll discuss this expression in detail shortly.

  8. Save the report.

Note

The JavaScript in this example won’t execute in the Report Builder Preview. You need to save the report to SharePoint to see it work.

Expression builder with JavaScript pop-up window
Figure 26-22. Expression builder with JavaScript pop-up window

After saving the report, view the report from SharePoint. Simply click on a product line to launch the drill-down report in a pop-up.

Completed report with JavaScript pop-up
Figure 26-23. Completed report with JavaScript pop-up

Now that you’ve seen an example in action, let’s talk about the details of the expression that was constructed behind the scenes. It is as follows:

="javascript:void(window.open(
'http://sp2010/book/dave/_layouts/ReportServer/RSViewerPage.aspx?
rv:RelativeReportUrl=/book/dave/Reports/ProductLineDrillDown.rdl
&rp:ProductLine="+ Fields!ProductLine.Value + "
&rv:HeaderArea=None&rv:Toolbar=None
&rv:ParamMode=Collapsed','_new','toolbar=no, location=no,
directories=no, status=no, menubar=no, scrollbars=no, resizable=no, 
copyhistory=yes, width=600, height=350'))"

Let’s walk though each concept used in this expression. Web browsers can execute JavaScript in place of a hyperlink by using the javascript: someFunction() syntax:

javascript:alert('hello world')

To open a new window in JavaScript, you can use the window.open syntax:

window.open(someUrl, windowName, parameters)

Let’s build the URL to access the Reporting Services report dynamically and add on some special parameters that Reporting Services Integrated Mode accepts for URL access. Start with the URL to the Reporting Services viewer page that you are able to grab by browsing to your report inside SharePoint.

The ? begins the URL parameters that we are passing in.

Parameters beginning with rv: are Report Viewer parameters. For instance:

  • RelativeReportUrl= sets the path to the Reporting Services report.

  • HeaderArea=None hides the header at the top of the report.

  • Toolbar=None hides the toolbar.

  • ParamMode=Collapsed hides the parameter area.

Parameters beginning with rp: are the parameters that the report itself is looking for. Set the ProductLine parameter using the value of the Productline field in our dataset by appending it to our expression:

  • ProductLine= + Fields!ProductLine.Value

"'http://sp2010/book/dave/_layouts/ReportServer/RSViewerPage.aspx?
rv:RelativeReportUrl=/book/dave/Reports/ProductLineDrillDown.rdl
&rp:ProductLine=" + Fields!ProductLine.Value + "
&rv:HeaderArea=None&rv:Toolbar=None&rv:ParamMode=Collapsed"

Now, let’s set a bunch of optional parameters to control the look and feel of the new window:

'toolbar=no, location=no, directories=no, status=no, menubar=no,
scrollbars=no, resizable=no, copyhistory=yes, width=600, height=350'

Finally, by wrapping the entire window.open function inside the void() function, you are able to tell the browser not to redirect to a new URL when someone clicks on the hyperlink.

Summary

If you are a beginner with Reporting Services, you may want to try these examples a few times to become comfortable with the techniques. In this chapter, you created and styled charts by leveraging the Report Builder designer. You created both simple drill-down capability, as well as leveraged JavaScript to keep your users in context and open up a URL in a pop-up window.

In the next chapter, we’ll discuss other uses of Reporting Services including leveraging subscriptions to deliver your reports on a schedule, and data alerts to inform your users to conditions in the data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.127.37