5.42. Example - DrawMessage
Prev | Chapter 5. PHPlot Examples | Next

## 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:

- The image background should be drawn, rather than using a plain white background.

- The image border should be drawn too.

- Fonts should not be reset, allowing the custom setting for the `generic` font to be used.

- The text should be word-wrapped at 50 columns. The narrower wrap point is needed due to the larger font. Note that newlines in the text are preserved, and long lines are wrapped.

- The specified color (navy) should be used for the message text.

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

    <?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'));

Prev | Up | Next
5.41. Example - Pie Chart Label Types | Home | 5.43. Example - Custom Data Value Label Formatting