February 5, 2007 at 1:42 am
Hi all,
I am trying to customize the color schema of my report chart. For this i write a code in custom code window. but when i am trying to access the code in the fill color window in appereance of data value i am getting the error "Unrecognized Identifier". I am sending the procedure also which i followed:<script></script>
Custom Chart Color Palettes and Legends
Charts use built-in predefined color palettes with 10 to 16 distinct colors. Starting with Reporting Services 2000 Service Pack 1 (SP1), you can override the default colors. To specify color values as constant or expression-based values, click the Series Style button on the appearance properties for the data value in the Edit Chart Value dialog box. You could use this, for instance, to highlight values based on a certain condition such as a minimum or maximum value within the current series.
Note If you don't want to define a full custom color palette, you can override the color for individual data points. Use an expression that either returns a specific color value (in order to override) or returns "Nothing," which will pick the current color from the underlying built-in color palette.
For example, you want to highlight in red all data point values with negative y-values. For all the other data points, you want to apply the default colors. To do this, select Edit the data value and click the Appearance tab. Click the Series Style button, which opens the Style Properties dialog box. Click the Fill tab. Enter the following expression in the fill color style properties.
=iif(Sum(Fields!Sales.Value - Fields!Cost.Value) < 0, "Red", Nothing))
Note If you set the fill color to a constant value, this color is applied to all the data points for that data series.
The chart legend uses color fields to match the legend items to the visible data points. The legend can only show one color field per legend item (data series); hence, it shows the color of the first data point within that series. Remember this when you use expressions to dynamically determine the color of individual data points within a series; the legend item always shows the actual color of the first data point.
While the legend built into Reporting Services charts is easy to use, it lacks flexibility. For example, the legend consumes space within the chart. If the legend is placed outside the plot area and the legend grows, the chart plot area size shrinks accordingly.<script></script>
You can get more flexibility and control over the legend by generating your own custom legend by using a table or a matrix. The easiest way to synchronize the colors in the chart with your custom legend is to define your own custom chart color palette. The CustomColorPalette sample report implements a custom color palette and a custom legend. See Figure 14.
Figure 14. A bar chart report with a custom color palette and a custom legend
To build a custom color palette
Define the chart series groups and category groups.
By default, every chart data series has a color assigned to it. This color is based on the selected chart palette. In this example, we want to override these colors based on the series group instance values.
Define the custom color palette and add custom code.
The colorPalette variable stores the definition of our custom color palette, which has 15 distinct colors. The count variable keeps track of the total count of distinct grouping values in order to wrap around once we exceed the number of distinct colors in the custom color palette. The mapping hash table keeps track of the mapping between grouping values and colors. This ensures that all data points within the same data series have the same color. Later it is used to synchronize the custom legend colors with the chart colors. The following code goes into the custom code window of the report.
Private colorPalette As String() = {"Green", "Blue", "Red", "Orange",
"Aqua", "Teal", "Gold", "RoyalBlue", "MistyRose", "LightGreen",
"LemonChiffon", "LightSteelBlue", "#F1E7D6", "#E16C56", "#CFBA9B"}
Private count As Integer = 0
Private mapping As New System.Collections.Hashtable()
Public Function GetColor(ByVal groupingValue As String) As String
If mapping.ContainsKey(groupingValue) Then
Return mapping(groupingValue)<script></script>
End If
Dim c As String = colorPalette(count Mod colorPalette.Length)
count = count + 1
mapping.Add(groupingValue, c)
Return c
End Function
Call the GetColor() function to assign colors to data points.
The GetColor function is called from the fill color style properties. Edit the data value to open the Edit Chart Value dialog box and click the Appearance tab (Figure 15). Click the Series Style button and click the Fill tab. The current series group value is passed as an argument to the GetColor function, which is needed to map the internal group instance value to the color value.
Figure 15. Specifying explicit data series styles
Note If there are multiple chart series groups, you can concatenate the series group values to create a unique identifier that is used inside the GetColor function. The following code is an example.
=Code.GetColor(Fields!Country.Value & "|" & Fields!City.Value)
Add a chart legend.
You can use the built-in chart legend. Or, turn off the built-in chart legend and follow the steps in the next procedure to build your own custom chart legend with a table or a matrix data region.
To build a custom legend
Add a table data region to the report.
Place the table next to the chart and bind it to the same dataset as the chart.
Mirror the chart grouping structure in the table by adding table groups.
If the chart uses series groupings, add them to the table by adding table groups that are based on the same group expression as the one in the chart series groupings. Then add chart category groupings (if present) as inner table groups.
In general, if the chart has m series grouping and n category grouping, you add m+n table groups for your custom legend.
For the individual table groups, make sure to show only the group header (which will contain the legend description). Also, remove the table detail row unless you want to use the table detail rows to simulate a chart data table.<script></script>
Design the custom legend.
Add a rectangle for the color field of the custom legend. For example, you might add it to the first table column. As indicated in step 2, you should only have group header rows in the table. The rectangle goes into the innermost group header level.
Set the rectangle BackgroundColor property to the equivalent expression used on the chart data point's fill color. In the most trivial case, the expression would just contain one grouping value as in the following code.
=Code.GetColor(Fields!Country.Value)
For the legend text, use either the same expression as in the category and series group/label expressions, or experiment until you achieve the legend description text that you want.
Any pointers will be greatly appriciated.(
February 7, 2007 at 10:16 am
may be, in the first time to create the procedure this was wrong and the error was saved in the rdl and right now you procedure might correct, but this is not refresh
try to edit the rdl file (right click over report and select view code) to find the error
and check the procedure in other project only in VS
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply