Contents Previous Next

10.22 Using country flags in various context

JpGraph has built-in support for over 200 country flags, i.e. they are available to be used in graphs without any external image definitions.

Country flags can be used in primarily two settings

  1. As image markers in line and scatter graphs
  2. As background images for graphs
  3. As a special type of icons (using the IconPlot()) which can be added to the graph in any arbitrary position. See next section

In order to make it easy to find the appropriate country flags they can be specified with either full or partial name or as an numeric index. The routines in JpGraph are "smart" enough to figure out which way you are trying to specify a particular flag.

To specify a country flag as a marker you have to specify the special mark type as one of MARK_FLAG1,MARK_FLAG2,MARK_FLAG3 or MARK_FLAG4

Flags are internally stored in 4 different sizes which is indicated by the number in the mark types. Flags may also be arbitrary scaled when displayed. Since this is partially overlapping functionality you might very well ask why the flags are stored in four different basic sizes. The reason is of course performance. It you only want a very small flag it takes processing time to scale down a large image to, say, a small icon size. At the same time for large flags to be used as background a small original flag might not have enough details to be scaled up to a large size. Hence the reason for storing the flags in 4 different sizes.

The example below shows how to use country flags as markers

Figure 179: Using country flags as line plot markers [src] 

To use country flags as background one has to use the method Graph::SetBackgroundCountryFlag(). With this method you can specify both how much of the image should be filled as well as how much of the flag should be mixed into the background.

To see a list of all supported country flags you can run the script "listallcountryflags.php" in the Example directory. This will show you a table with all flags.

Contents Previous Next