5.42. Example - DrawMessage

This example uses DrawMessage to produce a warning message image instead of a plot image. In a real application, a PHPlot object would be created and set up for plotting, then some condition in the application code would determine that a plot could not be produced. Instead of producing a plot image, DrawMessage could be used to provide an image (as expected by the containing HTML page) with a message for the user.

The options supplied to DrawMessage in this example indicate that:

Note: This example uses a system-dependent TrueType font, and will need to be modified for other systems.

The DrawMessage function was added in PHPlot-5.7.0.

Example 5.42. DrawMessage

DrawMessage Example
<?php
# PHPlot Example: Use DrawMessage() to display a message
require_once 'phplot.php';

$plot = new PHPlot(600, 400);
# Note: This font name is system dependent:
$plot->SetFontTTF('generic', 'LiberationSans-Italic.ttf', 14);
$plot->SetBackgroundColor('#ffcc99');
$plot->SetImageBorderWidth(8);
$plot->SetImageBorderColor('blue');
$plot->SetImageBorderType('raised');
#
# Here you would start to produce the plot, then detect something wrong ...
#
$message = "I'm sorry, Dave. I'm afraid I can't do that.\n"
         . "\n"
         . "You haven't supplied enough data to produce a plot. "
         . "Please try again at another time.";
$plot->DrawMessage($message, array(
    'draw_background' => TRUE,
    'draw_border' => TRUE,
    'reset_font' => FALSE,
    'wrap_width' => 50,
    'text_color' => 'navy'));

SourceForge.net Logo

This version of the manual was produced for the PHPlot Sourceforge project web service site, which requires the logo on each page.

To download a logo-free copy of the manual, see the PHPlot project downloads area.