在使用报表服务设计报表时,只是使用默认提供的几种调色版看起来,不是很好看,其实可以定制调色版。
用C#生成一个带强命名的程序集(dll),如把下面的代码粘贴到一个文件,生成一个dll:
调色版
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Security;
5
6namespace CustColorPalettes
7{
8
9 public class ColorPalettes
10 {
11 private String[] colorPalette = new string[] { "#95DDFF", "#B4FD79", "#D5B6FE", "#F5FF95", "#95EEFF", "#FEB3BB", "#FFDD95", "#959FFF", "#E4FF95", "#FF959F", "#AFEEEE", "#FEF1BC", "#FF95D4", "#E4FEBC", "#FEC79D", "#D3BCFE", "#FFFB95", "#AFD0EE", "#FEB3E1", "#95FFF5", "#95D6FF", "#FEFF95", "#FFB3A7", "#BEEDD7", "#7BFEC5" };
12 private int count = 0;
13 private System.Collections.Hashtable mapping = new System.Collections.Hashtable();
14 public string GetStartColor(String groupingValue)
15 {
16 if (mapping.ContainsKey(groupingValue))
17 return mapping[groupingValue].ToString();
18
19 String c = colorPalette[count % colorPalette.Length];
20 count = count + 1;
21 mapping.Add(groupingValue, c);
22 return c;
23 }
24 private string[] colorPalette1 = new string[] { "#016593", "#348801", "#6B0193", "#869400", "#007B94", "#560935", "#946400", "#000D94", "#6E9301", "#94000E", "#004F4F", "#733318", "#940057", "#4F4700", "#9B4504", "#11195F", "#FFFB95", "#002D4F", "#47004F", "#009487", "#003F94", "#946800", "#C83C23", "#424C50", "#018454" };
25 private int count1 = 0;
26 private System.Collections.Hashtable mapping1 = new System.Collections.Hashtable();
27 public string GetEndColor(String groupingValue)
28 {
29 if (mapping1.ContainsKey(groupingValue))
30 return mapping1[groupingValue].ToString();
31
32 String c = colorPalette1[count1 % colorPalette1.Length];
33 count1 = count1 + 1;
34 mapping1.Add(groupingValue, c);
35 return c;
36 }
37
38 }
39}
40
复制上面DLL文件到如下目录:
在布署时,请复制此DLL文件到(假设sql2005安装在:C:\Program Files\Microsoft SQL Server):
C:\Program Files\Microsoft SQL Server\MSSQL.4\Reporting Services\ReportManager\Bin
C:\Program Files\Microsoft SQL Server\MSSQL.4\Reporting Services\ReportServer\bin
在设计报表时,请复制此DLL到:
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies