Subversion Repositories cheapmusic

Rev

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 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.
</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 plain
        white 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 wrap
        point is needed due to the larger font. Note that newlines in the
        text 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 to
be 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">&lt;?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-&gt;SetFontTTF('generic', 'LiberationSans-Italic.ttf', 14);
$plot-&gt;SetBackgroundColor('#ffcc99');
$plot-&gt;SetImageBorderWidth(8);
$plot-&gt;SetImageBorderColor('blue');
$plot-&gt;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-&gt;DrawMessage($message, array(
    'draw_background' =&gt; TRUE,
    'draw_border' =&gt; TRUE,
    'reset_font' =&gt; FALSE,
    'wrap_width' =&gt; 50,
    'text_color' =&gt; '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>