|
Q. How do I use a custom chart type in Reporting Services?
A.
You need the custom chart type DLL and you need to write some additional
code in the PostApplyData event.
Dundas Chart comes with many standard chart types including bar,
line, area, and pie charts just to name a few. Depending on the kind of
data you have, a different style of
chart would be more appropriate. This is where Custom Chart types come
into play.
Starting with version 3.0 several custom chart types are now included
when you install Dundas Chart for Reporting Services. Below is a list
of the included custom charts (the links go to their
online documentation):
After installing Dundas Chart for Reporting Services, you will find
the necessary DLLs for the above chart types in the bin folder located
(by default) at:
C:\Program Files\Dundas Software\Charting\Reporting Services\bin\
If you are using Reporting Services for SQL 2008, they will be in the
\Reporting Services 2008\ folder.
To learn more about custom chart types in general including how to
create your own, visit the
Custom Chart Types Documentation.
Getting started
This article will show you the simple steps involved in using a custom
chart type in your report. For this particular demo we will be creating
a TreeMap chart type, which is essentially a heat map,
however rather than one series there will be multiple series, each with
its own individual group of data points.
We will be doing this using Dundas Chart 3.1 for Reporting Services
2005, Visual Studio 2005 and HeatMap version 2.0 (or higher). HeatMap
versions below 2.0 do not support TreeMap.
Below is the sample output that will be produced using the steps shown
in this article.
Step 1 — Copy the DLLs
To use custom chart types, you need to be sure the
appropriate DLLs are in their respective directories. On the developer
machines, the DLLs will be in the Private Assemblies folder.
On the production Report Server, the DLLs will be in the Report Server’s bin
folder.
After installing Dundas Chart for Reporting Services go into
the installation's bin folder and copy the HeatMapRS.DLL and
CustomChartTypeHelperRS.DLL files to the Visual Studio Private
Assemblies folder as well as to your Report Server’s bin folder.
Also in the above folders you should find DundasChartRS.dll.
The installation should have already placed this DLL in the
Private Assemblies folder. For the DLL to be in the Report
Server please follow this article located on our support site.
Note: Your exact folders for Visual Studio and SQL Server may differ
depending on how and where you have installed the two products. Please
contact your administrator if you are unsure about the locations.
Step 2 — Create the report and connect to your data
Begin by creating a Report Project and adding a Report file (.RDL) to
the project.
We will be creating a shared data source that connects to the master
database on the local SQL server and then return a static dataset
containing the data we will be binding to the tree map.
Step 3 — Create the basic chart
Since the Heat Map uses two values per data points to represent its data
(high and low) we will use the Range chart type since the Chart
Wizard will let you assign these values at design time.
After dropping the chart onto the report, in the wizard that comes up
make sure to select the Range chart type. On the next page, setup your
various fields and groups as shown:
Step 4 — Set advanced data properties
When you use Series Grouping, Dundas Chart will automatically create
the series for you. To name the series the same as the data
in one of the columns as well as to assign additional properties to the
datapoints, we will need to set up advanced data binding.
Begin by going into the Series properties and clicking on the Advanced
button.
To bring up the box shown, right click on the Chart
and click Properties.
In the Chart Designer window, select the Data tab. Then click the
series in the Values: list and click the Properties button located
directly above it as shown:
After clicking the Properties button shown above, another window will
come up. Click the Advanced button located in the Values tab to bring
up the window shown here. In this window you will add a
single property called SeriesName with a value of =Fields!Name.Value
which will be an expression for the Name field.
Step 5 — Preview the chart
At this point we should be able to preview our chart and see that it
looks like a basic range chart.
Once we can preview this, we can now proceed to the final few steps
which will actually convert this chart into a tree map chart.
Step 6 — Include the custom chart type DLL
To include external DLLs (assemblies) into our project right click on
the Chart and click View Code.
In the window that comes up, go to the External Assemblies tab and add
the HeatMapRS.DLL assembly.
You will have to browse to the Private Assemblies folder (as described
in Step 1) and select the HeatMapRS.DLL file.
Step 7 — Add code to activate the custom chart type
With the chart working fine as a Range chart type, and the HeatMapRS.DLL
in place we can finish by adding the necessary code-behind to convert
the chart to a HeatMap.
Right click on the Chart and pick View Code. In the Code Editor, change
to the PostApplyData event and change the language to C#.
In the code editor, enter the code shown below. The first two
portions of code are the most important in that it will register the
HeatMapRS.DLL so that our chart can be rendered as a HeatMap. The rest
of the code alters some of the custom HeatMap properties as well as
assigning a series name.
Dundas.Charting.WebControl.ChartTypes.ChartTypeRegistry registry =
(Dundas.Charting.WebControl.ChartTypes.ChartTypeRegistry)chartObj.GetService(typeof(
Dundas.Charting.WebControl.ChartTypes.ChartTypeRegistry));
registry.Register(typeof(Dundas.Extensions.HeatMap).Name, typeof(Dundas.Extensions.HeatMap));
chartObj.ApplyPaletteColors();
foreach (Series series in chartObj.Series)
{
series.ChartType = typeof(Dundas.Extensions.HeatMap).Name;
series.BackGradientEndColor = Color.FromArgb(80,
series.Color.R,
series.Color.G,
series.Color.B);
series["FromText"] = "From: $#MINY1M";
series["ToText"] = "To: $#MAXY1M";
series["MaxCharacters"] = "24";
foreach (DataPoint dp in series.Points)
{
if (dp["SeriesName"] != null)
{
series.Name = dp["SeriesName"].ToString();
break;
}
}
}
Conclusion
As you can see, using Custom chart types is very easy to do in Reporting
Services. Using the steps above you should be able to easily use any
one of the other custom chart types in your report projects.
To summarize the above steps:
- Be sure the appropriate DLLs are in their respective directories on both developer machine and production report servers.
- Add the DLL to the report project as an External Assembly.
- Add the necessary code-behind to convert a regular chart type to a custom chart type.
|