In This Topic
Several objects in the chart and gauge have an associated palette object. These include the bar series, area series, high-low series, heat map series, treemap chart, linear and radial range indicators, and others. The palette object's purpose is to map a value to a color to increase readability or to convey additional information to the users. For example in a surface chart the data point value may represent altitude and the color may represent temperature.
The different palette classes derive from the NPalette base class and they represent different color mapping strategies, the common being that each palette maps a value from a range of values to a specific color. If the palette does not contain an explicit color for a specific value then the palette will use the color of the closest value which is lesser than the value being mapped. Alternatively you can specify that the palette must interpolate the colors corresponding to the closes values in the palette. This is done by setting the InterpolateColors property of the palette to true:
C# |
Copy Code
|
palette.InterpolateColors = true;
|
The following sections describe those different palette classes:
Two Color Palette
The two-color palette maps a range of values to a begin and end color. Optionally values between the begin / end of the range can be interpolated between the begin and end color. The two color palette is represented by the NTwoColorPalette class. The following code shows how to create such a palette:
C# |
Copy Code
|
someObject.Palette = new NTwoColorPalette(NColor.Red, NColor.Green);
|
Three Color Palette
The three-color palette maps a range of values to colors using a set of three colors and an origin value. This is done using the following rules:
1. If both the begin and end values of the range are less than the origin value the begin value is mapped to the begin color and the end value is mapped to the interpolated color between the begin color and the origin color.
2. If the begin value is less than the origin value and the end value is bigger than the origin value then the begin value is mapped to the begin color, the origin value is mapped to the origin color, and the end value is mapped to the end color.
3. If both the begin and end values of the range are bigger than the origin value then the begin value is mapped to the interpolated color between the origin color and the end color and the end value is mapped to the end color.
This type of palette is generally used in charts that need a color for positive and negative changes (for example treemap charts).
The following code snippet shows how to create a three-color palette:
C# |
Copy Code
|
someObject.Palette = new NThreeColorPalette(NColor.Red, NColor.Green, NColor.White, 0);
|
This palette will color negative values in red and positive values in green.
Color Value Palette
The color value palette maps a set of values to a set of colors. The following code snippet shows how to create this type of palette:
C# |
Copy Code
|
someObject.Palette = new NColorValuePalette(new NColorValuePair[] { new NColorValuePair(0.0, NColor.Purple),
new NColorValuePair(1.5, NColor.MediumSlateBlue),
new NColorValuePair(3.0, NColor.CornflowerBlue),
new NColorValuePair(4.5, NColor.LimeGreen),
new NColorValuePair(6.0, NColor.LightGreen),
new NColorValuePair(7.5, NColor.Yellow),
new NColorValuePair(9.0, NColor.Orange),
new NColorValuePair(10.5, NColor.Red) });
|
The principle on which this palette maps colors is:
- if a value is below the minimum value then the corresponding color is the color mapped to the minimum value.
- if a value is above the maximum value then the corresponding color is the color mapped to the maximum value.
- if a value is between two values then the corresponding color is the interpolated color depending on the distance of the value to the nearest palette values.
Range Multi Color Palette
This type of palette is a type of multi-color palette that automatically generates color-value pairs based on a specified set of colors and the palette range. The following code shows how to create a range multi-color palette:
C# |
Copy Code
|
NRangeMultiColorPalette palette = new NRangeMultiColorPalette(new NColor[] { NColor.Red, NColor.Orange, NColor.Yellow, NColor.LightGreen });
|
Axis Ticks Palette
This type of palette is a type of multi-color palette that automatically generates color-value pairs based on a specified set of colors and the values of the major axis ticks. It is useful when you want to synchronize the appearance of the object with the axis ticks and grid lines. The following code shows how to create an axis ticks palette:
C# |
Copy Code
|
this.Palette = new NAxisTicksPalette(new NColor[] {
NColor.Red, NColor.Orange, NColor.Yellow, NColor.LightGreen });
|