Blame | Last modification | View Log | RSS feed
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>5.42. Example - DrawMessage</title><link rel="stylesheet" type="text/css" href="phplotdoc.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /><link rel="home" href="index.html" title="PHPlot Reference Manual" /><link rel="up" href="examples.html" title="Chapter 5. PHPlot Examples" /><link rel="prev" href="ex-pielabeltype.html" title="5.41. Example - Pie Chart Label Types" /><link rel="next" href="ex-dlexformat.html" title="5.43. Example - Custom Data Value Label Formatting" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.42. Example - DrawMessage</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-pielabeltype.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-dlexformat.html">Next</a></td></tr></table><hr /></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ex-drawmessage"></a>5.42. Example - DrawMessage</h2></div></div></div><p>This example uses <a class="xref" href="DrawMessage.html" title="DrawMessage"><span class="refentrytitle">DrawMessage</span></a> to produce a warning messageimage instead of a plot image. In a real application, a PHPlot object wouldbe created and set up for plotting, then some condition in the applicationcode would determine that a plot could not be produced. Instead ofproducing a plot image, DrawMessage could be used to provide an image (asexpected by the containing HTML page) with a message for the user.</p><p>The options supplied to DrawMessage in this example indicate that:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>The image background should be drawn, rather than using a plainwhite background.</p></li><li class="listitem"><p>The image border should be drawn too.</p></li><li class="listitem"><p>Fonts should not be reset, allowing the custom setting for the<code class="literal">generic</code> font to be used.</p></li><li class="listitem"><p>The text should be word-wrapped at 50 columns. The narrower wrappoint is needed due to the larger font. Note that newlines in thetext are preserved, and long lines are wrapped.</p></li><li class="listitem"><p>The specified color (navy) should be used for the message text.</p></li></ul></div><p></p><p>Note: This example uses a system-dependent TrueType font, and will need tobe modified for other systems.</p><p>The DrawMessage function was added in PHPlot-5.7.0.</p><div class="example"><a id="example-drawmessage"></a><p class="title"><strong>Example 5.42. DrawMessage</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/drawmessage.png" alt="DrawMessage Example" /></div></div><pre class="programlisting"><?php# PHPlot Example: Use DrawMessage() to display a messagerequire_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'));</pre></div></div><br class="example-break" /></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ex-pielabeltype.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="examples.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ex-dlexformat.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.41. Example - Pie Chart Label Types </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.43. Example - Custom Data Value Label Formatting</td></tr></table></div></body></html>