1 //------------------------------------------------------------- 2 // <copyright company=�Microsoft Corporation�> 3 // Copyright � Microsoft Corporation. All Rights Reserved. 4 // </copyright> 5 //------------------------------------------------------------- 6 // @owner=alexgor, deliant 7 //================================================================= 8 // File: ColorPalette.cs 9 // 10 // Namespace: System.Web.UI.WebControls[Windows.Forms].Charting 11 // System.Web.UI.WebControls[Windows.Forms].Charting.Utilities 12 // 13 // Classes: ChartPaletteColors 14 // 15 // Purpose: A utility class which defines chart palette colors. 16 // These palettes are used to assign unique colors to 17 // different chart series. For some chart types, like 18 // Pie, different colors are applied on the data point 19 // level. 20 // 21 // Selected chart series/points palette is exposed 22 // through Chart.Palette property. Series.Palette 23 // property should be used to set different palette 24 // color for each point of the series. 25 // 26 // Reviewed: AG - August 7, 2002 27 // AG - Microsoft 5, 2007 28 // 29 //=================================================================== 30 31 #region Used Namespaces 32 33 using System; 34 using System.Drawing; 35 36 #if Microsoft_CONTROL 37 using System.Windows.Forms.DataVisualization.Charting; 38 #else 39 using System.Web.UI.DataVisualization.Charting; 40 #endif 41 #endregion 42 43 #if Microsoft_CONTROL 44 namespace System.Windows.Forms.DataVisualization.Charting 45 #else 46 namespace System.Web.UI.DataVisualization.Charting 47 48 #endif 49 { 50 #region Color palettes enumeration 51 52 /// <summary> 53 /// Chart color palettes enumeration 54 /// </summary> 55 public enum ChartColorPalette 56 { 57 /// <summary> 58 /// Palette not set. 59 /// </summary> 60 None, 61 62 /// <summary> 63 /// Bright palette. 64 /// </summary> 65 Bright, 66 67 /// <summary> 68 /// Palette with gray scale colors. 69 /// </summary> 70 Grayscale, 71 72 /// <summary> 73 /// Palette with Excel style colors. 74 /// </summary> 75 Excel, 76 77 /// <summary> 78 /// Palette with LightStyle style colors. 79 /// </summary> 80 Light, 81 82 /// <summary> 83 /// Palette with Pastel style colors. 84 /// </summary> 85 Pastel, 86 87 /// <summary> 88 /// Palette with Earth Tones style colors. 89 /// </summary> 90 EarthTones, 91 92 /// <summary> 93 /// Palette with SemiTransparent style colors. 94 /// </summary> 95 SemiTransparent, 96 97 /// <summary> 98 /// Palette with Berry style colors. 99 /// </summary> 100 Berry, 101 102 /// <summary> 103 /// Palette with Chocolate style colors. 104 /// </summary> 105 Chocolate, 106 107 /// <summary> 108 /// Palette with Fire style colors. 109 /// </summary> 110 Fire, 111 112 /// <summary> 113 /// Palette with SeaGreen style colors. 114 /// </summary> 115 SeaGreen, 116 117 /// <summary> 118 /// Bright pastel palette. 119 /// </summary> 120 BrightPastel 121 }; 122 123 #endregion 124 } 125 126 #if Microsoft_CONTROL 127 namespace System.Windows.Forms.DataVisualization.Charting.Utilities 128 #else 129 namespace System.Web.UI.DataVisualization.Charting.Utilities 130 #endif 131 { 132 /// <summary> 133 /// ChartPaletteColors is a utility class which provides access 134 /// to the predefined chart color palettes. These palettes are 135 /// used to assign unique colors to different chart series. 136 /// For some chart types, like Pie, different colors are applied 137 /// on the data point level. 138 /// 139 /// GetPaletteColors method takes a ChartColorPalette enumeration 140 /// as a parameter and returns back an array of Colors. Each 141 /// palette contains different number of colors but it is a 142 /// good practice to keep this number around 15. 143 /// </summary> 144 internal static class ChartPaletteColors 145 { 146 #region Fields 147 148 // Fields which store the palette color values 149 private static Color[] _colorsGrayScale = InitializeGrayScaleColors(); 150 private static Color[] _colorsDefault = { 151 Color.Green, 152 Color.Blue, 153 Color.Purple, 154 Color.Lime, 155 Color.Fuchsia, 156 Color.Teal, 157 Color.Yellow, 158 Color.Gray, 159 Color.Aqua, 160 Color.Navy, 161 Color.Maroon, 162 Color.Red, 163 Color.Olive, 164 Color.Silver, 165 Color.Tomato, 166 Color.Moccasin 167 }; 168 169 private static Color[] _colorsPastel = { 170 Color.SkyBlue, 171 Color.LimeGreen, 172 Color.MediumOrchid, 173 Color.LightCoral, 174 Color.SteelBlue, 175 Color.YellowGreen, 176 Color.Turquoise, 177 Color.HotPink, 178 Color.Khaki, 179 Color.Tan, 180 Color.DarkSeaGreen, 181 Color.CornflowerBlue, 182 Color.Plum, 183 Color.CadetBlue, 184 Color.PeachPuff, 185 Color.LightSalmon 186 }; 187 188 private static Color[] _colorsEarth = { 189 Color.FromArgb(255, 128, 0), 190 Color.DarkGoldenrod, 191 Color.FromArgb(192, 64, 0), 192 Color.OliveDrab, 193 Color.Peru, 194 Color.FromArgb(192, 192, 0), 195 Color.ForestGreen, 196 Color.Chocolate, 197 Color.Olive, 198 Color.LightSeaGreen, 199 Color.SandyBrown, 200 Color.FromArgb(0, 192, 0), 201 Color.DarkSeaGreen, 202 Color.Firebrick, 203 Color.SaddleBrown, 204 Color.FromArgb(192, 0, 0) 205 }; 206 207 private static Color[] _colorsSemiTransparent = { 208 Color.FromArgb(150, 255, 0, 0), 209 Color.FromArgb(150, 0, 255, 0), 210 Color.FromArgb(150, 0, 0, 255), 211 Color.FromArgb(150, 255, 255, 0), 212 Color.FromArgb(150, 0, 255, 255), 213 Color.FromArgb(150, 255, 0, 255), 214 Color.FromArgb(150, 170, 120, 20), 215 Color.FromArgb(80, 255, 0, 0), 216 Color.FromArgb(80, 0, 255, 0), 217 Color.FromArgb(80, 0, 0, 255), 218 Color.FromArgb(80, 255, 255, 0), 219 Color.FromArgb(80, 0, 255, 255), 220 Color.FromArgb(80, 255, 0, 255), 221 Color.FromArgb(80, 170, 120, 20), 222 Color.FromArgb(150, 100, 120, 50), 223 Color.FromArgb(150, 40, 90, 150) 224 }; 225 226 private static Color[] _colorsLight = { 227 Color.Lavender, 228 Color.LavenderBlush, 229 Color.PeachPuff, 230 Color.LemonChiffon, 231 Color.MistyRose, 232 Color.Honeydew, 233 Color.AliceBlue, 234 Color.WhiteSmoke, 235 Color.AntiqueWhite, 236 Color.LightCyan 237 }; 238 239 private static Color[] _colorsExcel = { 240 Color.FromArgb(153,153,255), 241 Color.FromArgb(153,51,102), 242 Color.FromArgb(255,255,204), 243 Color.FromArgb(204,255,255), 244 Color.FromArgb(102,0,102), 245 Color.FromArgb(255,128,128), 246 Color.FromArgb(0,102,204), 247 Color.FromArgb(204,204,255), 248 Color.FromArgb(0,0,128), 249 Color.FromArgb(255,0,255), 250 Color.FromArgb(255,255,0), 251 Color.FromArgb(0,255,255), 252 Color.FromArgb(128,0,128), 253 Color.FromArgb(128,0,0), 254 Color.FromArgb(0,128,128), 255 Color.FromArgb(0,0,255)}; 256 257 private static Color[] _colorsBerry = { 258 Color.BlueViolet, 259 Color.MediumOrchid, 260 Color.RoyalBlue, 261 Color.MediumVioletRed, 262 Color.Blue, 263 Color.BlueViolet, 264 Color.Orchid, 265 Color.MediumSlateBlue, 266 Color.FromArgb(192, 0, 192), 267 Color.MediumBlue, 268 Color.Purple 269 }; 270 271 private static Color[] _colorsChocolate = { 272 Color.Sienna, 273 Color.Chocolate, 274 Color.DarkRed, 275 Color.Peru, 276 Color.Brown, 277 Color.SandyBrown, 278 Color.SaddleBrown, 279 Color.FromArgb(192, 64, 0), 280 Color.Firebrick, 281 Color.FromArgb(182, 92, 58) 282 }; 283 284 private static Color[] _colorsFire = { 285 Color.Gold, 286 Color.Red, 287 Color.DeepPink, 288 Color.Crimson, 289 Color.DarkOrange, 290 Color.Magenta, 291 Color.Yellow, 292 Color.OrangeRed, 293 Color.MediumVioletRed, 294 Color.FromArgb(221, 226, 33) 295 }; 296 297 private static Color[] _colorsSeaGreen = { 298 Color.SeaGreen, 299 Color.MediumAquamarine, 300 Color.SteelBlue, 301 Color.DarkCyan, 302 Color.CadetBlue, 303 Color.MediumSeaGreen, 304 Color.MediumTurquoise, 305 Color.LightSteelBlue, 306 Color.DarkSeaGreen, 307 Color.SkyBlue 308 }; 309 310 private static Color[] _colorsBrightPastel = { 311 Color.FromArgb(65, 140, 240), 312 Color.FromArgb(252, 180, 65), 313 Color.FromArgb(224, 64, 10), 314 Color.FromArgb(5, 100, 146), 315 Color.FromArgb(191, 191, 191), 316 Color.FromArgb(26, 59, 105), 317 Color.FromArgb(255, 227, 130), 318 Color.FromArgb(18, 156, 221), 319 Color.FromArgb(202, 107, 75), 320 Color.FromArgb(0, 92, 219), 321 Color.FromArgb(243, 210, 136), 322 Color.FromArgb(80, 99, 129), 323 Color.FromArgb(241, 185, 168), 324 Color.FromArgb(224, 131, 10), 325 Color.FromArgb(120, 147, 190) 326 }; 327 328 #endregion 329 330 #region Constructor 331 332 /// <summary> 333 /// Initializes the GrayScale color array 334 /// </summary> InitializeGrayScaleColors()335 private static Color[] InitializeGrayScaleColors() 336 { 337 // Define gray scale colors 338 Color[] grayScale = new Color[16]; 339 for(int i = 0; i < grayScale.Length; i++) 340 { 341 int colorValue = 200 - i * (180/16); 342 grayScale[i] = Color.FromArgb(colorValue, colorValue, colorValue); 343 } 344 345 return grayScale; 346 } 347 348 #endregion 349 350 #region Methods 351 352 /// <summary> 353 /// Return array of colors for the specified palette. Number of 354 /// colors returned varies depending on the palette selected. 355 /// </summary> 356 /// <param name="palette">Palette to get the colors for.</param> 357 /// <returns>Array of colors.</returns> GetPaletteColors(ChartColorPalette palette)358 public static Color[] GetPaletteColors(ChartColorPalette palette) 359 { 360 switch(palette) 361 { 362 case(ChartColorPalette.None): 363 { 364 throw (new ArgumentException(SR.ExceptionPaletteIsEmpty)); 365 } 366 case(ChartColorPalette.Bright): 367 return _colorsDefault; 368 case(ChartColorPalette.Grayscale): 369 return _colorsGrayScale; 370 case(ChartColorPalette.Excel): 371 return _colorsExcel; 372 case(ChartColorPalette.Pastel): 373 return _colorsPastel; 374 case(ChartColorPalette.Light): 375 return _colorsLight; 376 case(ChartColorPalette.EarthTones): 377 return _colorsEarth; 378 case(ChartColorPalette.SemiTransparent): 379 return _colorsSemiTransparent; 380 case(ChartColorPalette.Berry): 381 return _colorsBerry; 382 case(ChartColorPalette.Chocolate): 383 return _colorsChocolate; 384 case(ChartColorPalette.Fire): 385 return _colorsFire; 386 case(ChartColorPalette.SeaGreen): 387 return _colorsSeaGreen; 388 case(ChartColorPalette.BrightPastel): 389 return _colorsBrightPastel; 390 } 391 return null; 392 } 393 394 #endregion 395 } 396 } 397