Continue to translate the jpgraph help document in the form of a Chinese PHP Tutorial. today we will introduce how to control the color of charts when using jpgraph, description of naming methods for several colors in the jpgraph class library continue to translate the jpgraph help document in the form of a Chinese PHP Tutorial. today we will introduce how to control the color of charts when using jpgraph, it mainly describes the naming methods of several colors in the jpgraph class library, how to control the color transparency and brightness, and how to mark the color transparency and brightness during use. It is helpful for developers who want to create charts using jpgraph.
Using appropriate colors is an important part of creating clear and intuitive charts. To simplify color processing, jpgraph supports several methods to adjust and operate colors, such as by name or value.
Almost all color settings of all objects are named in two ways.
SetColor ()Set the outline color or set this color if the object has only one color (such as a font ).
SetFillColor ()Fill in the color of the object in the specified area.
Both methods require a parameter to identify the color.
Specify color by color name
Jpgraph has a set of names corresponding to standard colors. For more information, see the ing relationship between the color names in Appendix D in the jpgraph English document.
SetColor ('white ')
SetFillColor ('Orange ')
When you do not need to replace the variable, always use the single quotation mark string to make it faster and more convenient.
Specify colors using RGB values
The use of the named color depends on the color known to the jpgraph class library. Manually specify other colors if needed.
The first method is to use the RGB value to specify the color, that is, the red, green, and blue colors. Each component is composed of integers ranging from 0. For example
SetColor (array (255,255,255 ))
SetColor (array (0xff, 0xff, 0xff ))
SetFillColor (array (0 × 44,0 × 54, 0xa4 ))
Common arraysArray (255,255,255, 0) indicates black, array () indicates white.
Use HTML color to specify
The second method is to use a hexadecimal RGB value similar to the RGB array, that is, the color used in the HTML webpage, such
SetColor ('#333'). Note that it is a short format, consistent with SetColor ('#333333 ').
SetColor ('# 12be7a ')
SetFillColor ('#99eff5 ′)
Fine-tuning of colors
This section mainly introduces the color transparency and brightness control.
Specify alpha channel (color transparency)
By specifying the transparency, the color can also become translucent.
The alpha channel can specify numbers in the range of 0.0-1.0 to specify the color transparency. The value 0.0 indicates opacity, and the value 1.0 indicates full transparency. that is, only the background color is displayed. Transparency is added by @ characters. It is usually used in area filling (that is, when the SetFillColor () method is used), such
SetFillColor ('red @ 0.2 '), slightly transparent red
SetFillColor ('red @ 0.8 '), almost transparent color
The effects of different alpha values are as follows: when blue becomes more transparent, the red bar chart becomes clearer.
Example of how to use jpgraph to control the transparency of colors
Adjust brightness using jpgraph
The brightness coefficient is separated by a character. The brightness value ranges from 0.0 to 2.0. The brightness coefficient 0.0 indicates that the color turns black (without any brightness), and the brightness 2.0 indicates that the color is white (maximum brightness ). Using coefficient 1 will change the color of the original image.
The brightness coefficient can be used in the named color name or HTML color, for example
SetColor ('red: 0.8 '), a little dark red
SetColor ('red: 1.5 '), bright hongse
SetColor ('#3485a9: 1.8), bright blue-green
Adjust the brightness of the named color and the brightness of the HTML color specifier,
Example of how to adjust the brightness of a color using jpgraph
How to adjust brightness and transparency
SetColor ('red @ 0.7: 1.2 ′)
SetFillColor ('#4545aa@0.3: 100 ′)
The first value after @ indicates transparency, and the second value indicates brightness.
Additional color processing instructions
Some plot types require additional color processing to facilitate processing and differentiation between datasets.
Pie plots
A pie chart supports the concept of a color topic. A color topic uses a simple set of colors for consecutive slices in a pie chart.
Color maps
Matrix (only in PRO version) and contour map also have the concept of Color maps.
Now, the jpgraph class library is used to process the color of the chart. the color transparency and brightness control supported by jpgraph are very practical, the color setting method and naming method are also very suitable for WEB designers.
Note: PHP website development tutorial -leapsoul.cn All rights reserved. When reprinting, please indicate the original source in the form of a link