Introduction: Greek Symbols
Working with graphs, and especially for mathematical type of graphs it is often useful to be able to use Greek characters and other mathematical symbols.
Using TTF fonts these character sets are already available but since many keyboard doesn't have these characters directly on the keyboard it requires some extra work to get hold of these characters. In this short note we show how to use the utility class SymChar available in the library (in 'jpgraph_utils.inc') to easily access some of these symbols.
The SymChar Class
In general characters not available directly on the keyboard are accessed through there key codes in the format of "ddddd". The SymChar class encapsulates these codes and make it easy to access the encoded symbols with the corresponding English name. For example the first three Greek characters are named "alpha", "beta", "gamma".
The symbols are accessed through a static method
The first argument should be the English name of the symbol and the second argument is a boolean value that indicates if the upper or lower case version of the symbol should be used. Note that not all symbols have a lower and upper case versions. Table 1 below shows the available symbols and the corresponding name.
Table 1. The name and symbols available in the SymChar class
It is necessary to use TTF fonts to have access to the extended symbol sets
To illustrate the usage let us add two Greek characters to a title of a graph. First we need to make sure we have the class available by including the utility file
Then we will assume we have already created a graph so that we have a Graph instance available. In this example we will add upper case versions of the two symbols delta and omega to the title of the graph.
$delta = SymChar::Get('delta',TRUE); $omega = SymChar::Get('omega',TRUE); $graph->title->Set('Ratio between '.$delta.' and '.$omega.' parameters'); $graph->title->SetFont(FF_TIMES,FS_BOLD,14);
In Figure 1. we have created a hypothetical graph with this title as illustration.
Figure 1. Greek symbols in the title and tick labels of a graph.
Also note that in Figure 1. we have positioned the ticks manually at multiples of 1/2 PI where each label also include a PI symbol. For more on manual tick positioning see HowTo: Manual tick marks