One reason for using TTF fonts is the possibility to inserting unicode character/entities. With this we mean characters from the extended range that are not normally available on West european keyboards. This could for example be classical Greek characters often used in mathematics, for example the symbol for "pi". In order to make these and other commonly used "special" characters more accessible the library provides a utility class that makes it easy to use these characters without having to look up the corresponding unicode entities every time.
In order to specify characters not available on the keyboard the normal way is to
specify there unicode code and included it in the text string with the prefix
"&#". For example the unicode for the character "pi" is "03C0" in hex so to
include this character in a text string you would have to write "This is pi
π" note that the code should be given in decimal encoding in the string
and always use 4 digits (pre-padded with 0:s as necessary). Since it is very tedious
to lookup and encode special characters the library offers a simpler way. The
This section can be skipped at first reading without loss of continuity.
As described above it is tedious to have to lookup all the character codes. To simplify this the SymChar class allows you to find these characters with the english common name of these symbols instead. For example to create a string with the Greek character "pi" one would have to write the code as shown in.
Example 8.2. Using the SymChar class to display the Greek letter "pi"
1 2 3 4 5 6
// ... $pi = SymChar::Get('pi'); $graph->title->Set('Test is pi'.$pi); // ...
All supported entities with there symbolic names are listed in Table 8.3. Supported character entities in class SymChar. The first argument to the static method
SymChar::Get() should be the name of the entity and if the
second optional argument is true then the capital version (if it exists) of the
symbol should be returned.
Table 8.3. Supported character entities in class SymChar
Figure 8.6. Rendered symbol characters corresponding to and Figure 8.7. Rendered capital symbol characters corresponding to Table 8.3. Supported character entities in class SymChar. shows how these symbol look when they are rendered with the TTF font Times Roman 14pt. The symbols are in the same order as in the table above and are visually grouped by there category as specified in the column "Comment" in the table above.
Figure 8.7. Rendered capital symbol characters corresponding to Table 8.3. Supported character entities in class SymChar.
In Figure 8.8. Specifying manual ticks as fraction of Pi.
( we have used the previous discussed
SymChar class to more readily insert "π" characters in the
X-axis label. We highlight some functionality that we haven't yet discussed in
We use a utility class (
FuncGenerator available in
jpgraph_utils.inc.php") to help create
plot values from a mathematical expression. This will help create a
set of (x,y) points that can later on be used as the base for a data
The x-axis labels and the position of the tick marks on the x-axis are manually positioned and specified to be positioned at "even" fractions of π.
Figure 8.8. Specifying manual ticks as fraction of Pi.