Tutorial: Adding a Bar Chart to a Report (Report Designer)
A bar chart can be useful for showing category data horizontally in order to:
Improve readability of long category names.
Improve understandability of times plotted as values.
Compare the relative value of multiple series.
For more information, see Bar Charts (Report Builder 3.0 and SSRS).
What You Will Learn
In this tutorial, you will learn how to:
Define a data source and add a dataset to the report.
Add a bar chart to the report.
Format the axis labels, title, and legend of the chart.
Requirements
To use this tutorial, the system must have the following installed:
SQL Server Business Intelligence Development Studio.
Note
Business Intelligence (BI) Development Studio is not supported on Itanium-based computers. However, support for BI Development Studio is available for x64-based computers. If the SQL Server sample databases have been deployed on an Itanium-based computer, use BI Development Studio on either an x86-based or x64-based computer to modify and run the samples.
SQL Server with the AdventureWorks2008 sample database.
Estimated time to complete this tutorial: 15 minutes
To create a report server project
Click Start, point to Programs, point to Microsoft SQL Server 2008 R2, and then click Business Intelligence Development Studio.
On the File menu, point to New, and then click Project.
In the Project Types list, click Business Intelligence Projects.
In the Templates list, click Report Server Project.
In Name, type Bar Chart Tutorial.
Click OK to create the project.
The Tutorial project is displayed in Solution Explorer.
To define a data source for the bar chart
Click View and select Report Data. The Report Data pane appears in your Business Intelligence Development Studio environment.
In the Report Data pane, click the New drop down list, and click Data Source.
In the Data Source Properties dialog box, verify that Embedded connection is selected.
In the Type box, select Microsoft SQL Server.
In the connection string text box, type a valid connection string or click the Edit button to open the Connection Properties dialog box.
In the Connection Properties dialog box, type or select the name of your server in the Server name text box.
Select Use Windows Authentication or SQL Server Authentication and type a user name and password that has permissions to access the AdventureWorks2008 database.
In the Select or enter a database name list box, type or select AdventureWorks2008.
Click Text Connection.
Click OK to close the Connection Properties dialog box. In the Data Source Properties dialog box you will see the default data source name, DataSource1, and the connection string.
Click OK. The new data source is displayed in the Report Data pane.
To define a data set for your report
In the Report Data pane, right-click the data source and click Add Data Set.
In the Data Set Properties dialog box, verify that Text is selected for Query type.
In the Query text box, enter the following query:
SELECT [FullName] as 'Name' ,[2002] as 'SalesBeforeLast' ,[2003] as 'SalesLastYear' ,[2004] as 'SalesYTD' FROM [Sales].[vSalesPersonSalesByFiscalYears]
Click OK. The dataset fields are displayed in the Report Data pane.
To add a bar chart with sales information to your report
On the View menu, click Toolbox.
Double-click or drag a Chart to the design surface. The Select Chart Type dialog appears.
Click Bar to display a list of bar charts. Select the first bar chart icon in the list.
Click on the chart to bring up the chart handles. Drag the bottom-right corner of the chart to increase the size of the chart.
Drag the Name field from the Report Data pane to the chart. The Chart Data pane will appear next to the chart data. Drop the Name field in the Category Groups area.
Drag the SalesYTD and SalesLastYear fields from the Report Data pane and drop them to the Values area.
Click Preview to run the report. Your report should look similar to the following example:
You will notice that the chart does not label every category on the y-axis. This is due to an automatic algorithm that calculates an interval at which to display labels in order to prevent label collisions. If you want to display all categories on the chart, you must specify an axis interval of 1.
To display all sales persons along the category axis of a bar chart
Switch to Design view.
Right-click the y-axis and click Axis Properties.
In the Category Axis Properties dialog box, on the Axis Options page, type 1 for Interval.
Click OK.
Note
If the names on the axis are unreadable, consider increasing the size of your chart, or changing formatting options for the axis labels. For more information, see Formatting Axis Labels on a Chart (Report Builder 3.0 and SSRS).
Click Preview. Your report should look similar to the following example:
To improve the readability of the chart values, you might want to move the chart legend. For example, in a bar chart, where bars are shown horizontally, you can change the position of the legend so that it is above or below the chart area. This gives more horizontal space to the bars.
To display the legend below the chart area of a bar chart
Switch to Design view.
Right-click the legend on the chart.
Select Legend Properties.
For Legend position, select a different position. For example, set the position to the middle bottom option.
Note
You can also drag the legend to a new location directly on the design surface.
When the legend is placed at the top or bottom of a chart, the layout of the legend changes from vertical to horizontal. You can select a different layout from the Layout drop-down list.
Click OK.
Note
If the names in the legend are unreadable, you may want to consider increasing the size of your chart, or changing formatting options for the legend. For more information, see Formatting the Legend on a Chart (Report Builder 3.0 and SSRS).
Next, you can change the chart title and axis titles and add formatting.
To change the chart title above the chart area of a bar chart
Switch to Design view.
Right-click on the chart title at the top of the chart and click Title Properties.
Replace the Title text field with the following text: "Sales Person YTD vs. Last Year".
Click anywhere outside the text.
Click Preview. Your report should look similar to the following example:
Lastly, you can format the sales figures as currencies instead of regular numbers.
To format as currency the numbers on the horizontal axis
Switch to Design view.
Right-click the horizontal axis along the bottom of the chart and click Axis Properties.
In Label Format, under Category, click Currency. You can also specify a variety of options related to how the currency value is formatted.
Click Preview.
To filter the top 5 values on the bar chart
Switch to Design view.
Click the chart once to bring up the Chart Data pane.
Right-click the Name field that is in the Category Groups area.
Select Category Group Properties.
Click Filters. This brings up a list of filter expressions. By default, this list is empty.
Click Add. A new blank filter appears.
In the Expression box, type the following expression:
=Sum(Fields!SalesYTD.Value)
In the Operator list box, select Top N.
In the Value box, type =5
Click Preview. The chart shows five names, the top 5 salespeople from the sales data.
To sort the names in alphabetical order on the bar chart
Switch to Design view.
Click the chart once to bring up the Chart Data pane.
Right-click the Name field that is in the Category Groups area.
Select Category Group Properties.
Click Sorting. This brings up a list of sort expressions. By default, this list is empty.
Click Add. A new sort expression appears.
In the Sort by box, select the [Name] expression. This is equivalent to the expression =Fields!Name.Value
In the Order box, select Z to A.
Click Preview. The chart shows the names in alphabetical order from top to bottom.
See Also