Contents Previous Next

8.1.2 Displaying the values for each data point

As a final easy modification we can enable the display of the data value above each data point. The value is represented by the 'value' property in the plot. (You can read more about the possibilities of the display value in the class reference.)

To enable the display of the value you just need to call the Show() method of the value as in

 $lineplot->value-> Show()

Adding that line to the previous line plot would give the result shown below.

Figure 7: Displaying the value for each data point [src] 

We can of course change both color, font and format of the displayed value. So for example if we wanted the display values to be dark red, use a bold font and have a '$' in front we need to add the lines

 $lineplot->value ->SetColor("darkred");
$lineplot ->value->SetFont( FF_FONT1, FS_BOLD);
$lineplot ->value->SetFormat( "$ %0.1f");

This would then result in the following image

Figure 8: Making the display values a little bit more interesting [src] 

Note: You can achieve more advanced formatting by using not just the printf() style format string by a format callback function. This could allow you to change the displayed value with more advanced formatting such as displaying money values with "," to separate thousands.

Contents Previous Next