饭饭TXT > 学习管理 > 《Visual Studio 2010 高级编程(英文出书版)》作者:Nick Randolph/等【完结】 > [Visual.Studio.2010.高级编程].Professional.Visual.Studio.2010.txt

第 97 页

作者:Nick Randolph/等 当前章节:15373 字 更新时间:2026-6-18 14:51

of the group field. You can safely delete this column without affecting the grouping if this is not

the behavior you are after.

fiGure 30-10

Designing reports .

655

When you add a group that has a group header row, here are some things that

may improve your report layout. First delete the column it added, and then

set the first cell in the group header row to display the value of the field it is

grouping by. Then select all the cells in the group header row, right-click, and

select the Merge Cells menu item to turn them into a single cell (enabling the

grouping field’s value to stretch across the columns). You may also want to add a

border or background color to the group header row so it stands out.

By default there is no formatting applied to the table apart from a solid light gray border around the

cells (or technically the control in each cell). Often you will want to have a border around the

table, between columns, or even between individual cells. Or perhaps you want a line between

the table header and the data, and/or the table footer and the data.

In all of these cases the easiest way to set the borders is to select the

cells to apply a border to and use the Report Borders toolbar (as fiGure 30-11

shown in Figure 30-11) to set them.

Often you will also want to set a background color for the header row (and a foreground color to

match). The easiest way to do this is to select the cells and use the Background Color/Foreground

Color buttons from the Report Formatting

toolbar to select the color to use (shown in

Figure 30 - 12 ).fiGure 30-12

Matrix

The Matrix control is used for cross-tab reports (similar to Pivot Tables in Excel). Essentially,

a Matrix control groups data in two dimensions (both rows and columns), and you use it when

you have two variables and an aggregate field for each combination of the two. So, for example,

if you wanted to see the total sales per product

category in each country, this would be the perfect

control to use (see Figure 30-13). The variables would

be the product category and the country, and the

aggregate is the total revenue (of the products in that

category to that country). Matrices are one of the

most important and powerful controls in reporting,

because they really help enable useful information to

be extracted from raw data.

What stands out about using the Matrix control (over the Table control) is that you don’t know

what columns there will be at design time. Both the number of rows and columns for the matrix

(and their headers) will be dictated by the data.

fiGure 30-13

656 . chaPter 30 reporTing

When you drop a Matrix control on your report you will see that it contains

both a column header and a row header that intersect on a data cell (as

shown in Figure 30 - 14 ), and that both the Row Groups and Column Groups

panes at the bottom of the designer have grouping entries (whereas the Table

control only had a row grouping entry).

For this example, you will be using the example of displaying the total sales per product category

in each country described earlier. Your data source (a collection of custom objects specifi cally

created and populated as the source of data for this report) contains four fi elds: ProductCategory,

Country, Revenue, and OrderQuantity. What you need to do is drag the ProductCategory fi eld from

the Report Data tool window onto the row header (marked Rows), and the Country fi eld onto the

column header (marked Columns). Then drag the Revenue fi eld (or the OrderQuantity fi eld — either

one) onto the data cell (marked Data), and you ’ re done! Assuming the fi eld you are aggregating is

numeric, it will have automatically applied a SUM aggregate to the Revenue fi eld.

fiGure 30-14

The matrix is closely related to the Table control, and in fact both (along with

the List control discussed shortly) are the same core control under the covers

(called a Tablix). However, they are templated as separate controls in order to

distinguish their different uses. If you were to delete the column group (and its

related rows and columns), you effectively turn the Matrix control into a table.

The designer will have automatically inserted a header label into the top

left - hand cell, but generally you will want to delete it.

The matrix in the report designer will now look like Figure 30 - 15 ,

and after adding some formatting you will get an output similar

to that shown previously in Figure 30 - 13 when you generate the

report.

Like with the Table control, you can display totals, but the Matrix

control enables you to have column totals as well as row totals. When you right - click the data cell

you will fi nd that the Add Total menu item is actually a submenu (unlike the Table control), from

which you can select a Row total or a Column total.

The Matrix control doesn ’ t limit you to having just

one aggregate per “ intersection. ” For example, you

may want to show both the total revenue and quantity

for each country/product category. Simply drag

another fi eld to aggregate (such as the OrderQuantity

fi eld) next to the Revenue fi eld in the matrix, and it too will appear for each country (as shown in

Figure 30 - 16 ).

fiGure 30-15

fiGure 30-16

Designing reports .

657

You can also extend the matrix to show additional “dimensions” by having multiple row or column

groups. Again, simply drag the additional fields to group by into the appropriate position in the row/

column grouping header area.

list

Lists are a more freeform means of displaying data

than the Table and Matrix controls, and thus provide

a lot of flexibility in the display of the data. If you

were to drop a field directly onto a report you would

find that it only displays the field’s value in the

dataset’s first row, but the List control enables you

to define a template (as shown in Figure 30-17), and

enumerates through the data source, populating and

displaying that template for each row (or group).

Being yet another form of the same base control used by the Table and Matrix controls, you will

find that the List control shares many of the same features that they have.

image

The Image control is used to display an image

in your report. The source of this image can

be from within your project (as an embedded

image resource in your project), an external

image (specified by a file system path or

URL), or from a database field (a blob). When

you drop this control on a report, a window

is displayed enabling you to set these options

(and others such as its size, border, and so on)

as shown in Figure 30-18.

The options that appear will depend on the

source you have selected for the image from

the Select the Image Source drop-down box.

If you want to show external images (for

example, from a file path) there are two

things you must note. You must add a

protocol prefix to the location you specify

(for example, file://, http://, and so on), and

you must also set the EnableExternalImages property on the LocalReport object to true because

this is not enabled by default.

reportViewer.LocalReport.EnableExternalImages = true;

subreport

The Subreport control is used as a placeholder where the contents of another report can be inserted

into this report (enabling complex reports to be created). This is discussed in detail later in this chapter.

fiGure 30-17

fiGure 30-18

658 .

chaPter 30 reporTing

Chart

Charts provide a much more visual representation

of data, enabling patterns and anomalies in the

data to be easily identified.

When you drop a Chart control onto a report

it will immediately open the Select Chart Type

window (as shown in Figure 30-19), allowing you

to select from a wide range of available chart types.

You can always change the type of chart at a later

point by right-clicking it and selecting the Change

Chart Type menu item.

Double-clicking a chart will (like other controls)

put it into edit mode (as shown in Figure 30-20),

and you will find it consists of a number of sub-

controls. Depending on the type of chart you

choose it will have different controls arranged on its

surface. All chart types, however, have a title and legend

in addition to the chart itself. You can rearrange these

components (or delete them) as you see fit.

Charts consist of categories, series, and data — each

essentially representing an axis. Categories are used to

group data, data specifies the source of the values to

display, and series add additional “dimensions” that will

be determined when the report is generated (the same

concept upon which the Matrix control works). For

simple charts you will just configure the categories and

data axes, and more complex charts will use the series axis also.

When the chart is in edit mode it displays drop zones (one for each axis) alongside the chart, upon

which you can drop the fields that each should use. For more advanced charts you can drop multiple

fields in each drop zone for multiple groupings/value displays.

Using the same source of data that you used when generating the matrix report, you will start by

generating a simple bar chart (the total sales per

product category). Drop the Chart control onto

the report, set it to be a 3-D Clustered Bar chart,

and double-click it to put it into edit mode. Drop

the ProductCategory field onto the Category

zone, and the Revenue field onto the Data zone.

Change the chart and axes titles as you see fit,

and another thing you will want to do (in order

to show a label for every product category) is to

right-click the vertical axis, select Axis Labels

from the menu, and change the Interval from

Auto to 1. Now when you generate the report

you will get an output similar to Figure 30-21.

fiGure 30-19

fiGure 30-20

fiGure 30-21

Designing reports .

659

Note that currently the legend is of no real value, because in a bar chart it is designed to show the

series group values (which you aren’t using in this chart).

Now generate a chart that works much like the

Matrix control, by setting the series grouping to

add an additional dimension to your previous

chart (so that it now displays the total quantity

of sales for each product category per country).

Drag the Country field onto the Series zone and

run the report again. Now you will have the

total sales for each product category split out per

country, as shown in Figure 30-22.

Note how the legend now shows which bar color

represents each country, because you are now

making use of the series axis.

fiGure 30-22

Gauge

The Gauge control is yet another means of

visually representing the data. Gauges are

generally designed to display a single value

(although some gauges can each display a

fixed number of separate values). This can be

quite useful in displaying Key Performance

Indicators (KPIs), for example.

When you drop a Gauge control onto a report

it immediately opens the Select Gauge Type

window, as shown in Figure 30-23, allowing

you to select from a number of different

linear and radial gauge types.

fiGure 30-23

Note that, unlike the Chart control, you cannot change the type of gauge once it

has been created.

For this example you will use the Radial with Mini Gauge gauge. When

you put the gauge into edit mode (by double-clicking it) it displays a drop

zone above it (as shown in Figure 30-24), which will have one or more field

placeholders (depending on how many values the gauge can display). Your

selected gauge can display two values (one in the main gauge and one in the

mini gauge), so it will have two field placeholders. When you drop a field

from the Report Data window onto a field placeholder, you will note that it

fiGure 30-24

660 .

chaPter 30 reporTing

automatically applies an aggregate because it is only displaying a single value in its related gauge.

Numeric fields will automatically have a SUM aggregate applied, and other fields will have a

COUNT aggregate applied.

Gauges have a fixed scale, and you must specify the minimum and maximum values that it will

display. The nature of the Gauge control means that it won’t automatically determine these values.

To change these values you will need to select

the scale itself (as shown in Figure 30-24),

then right-click and select Scale Properties

from the menu. This brings up the window

shown in Figure 30-25.

Your example will have expected values of

up to 1 million, so you will set that as your

maximum value. You will leave the interval

options to be automatically determined (this

will alter which scale labels are displayed),

although you can change these if the output

is not as you desire. When dealing with very

small or very large values (as you are with

this example), it may be useful to set the

value of the Multiply Scale Labels By option.

Instead of showing large numbers on the

intervals, you can set that the value labels be

multiplied by 0.00001, meaning that it will

display 1 instead of 100000, 2 instead of

200000, and so on (making for a much less

cluttered gauge). In this case it would be important to add a label to the gauge (right-click it and

select Add Label from the menu) showing the multiplier that should be used with the label values to

get the real value being represented.

You can also add one or more ranges to your gauge. For example, you might want to indicate that

a range of values is acceptable by shading an area under the scale green, and shade another area

red indicating the value should be of concern. Right-click your gauge and

select Add Range from the menu. This automatically inserts a range into

your gauge — to configure it right-click and select Range Properties from the

menu. From this window you can enter at what values the range should start

目录
设置
设置
阅读主题
字体风格
雅黑 宋体 楷书 卡通
字体大小
适中 偏大 超大
保存设置
恢复默认
手机
手机阅读
扫码获取链接,使用浏览器打开
书架同步,随时随地,手机阅读
首 页 < 上一章 章节列表 下一章 > 尾 页