Menu

SampleDisclaimerText

PHPlot Sample - Adding Disclaimer Text

This example adds disclaimer text to the bottom of the plot. (2012-03-23)

Reference: Discussion forum thread

The Plot:

Plot Image

The Code:

~~~~
:::php
<?php

PHPlot example - add a disclaimer to a plot

Ref: forum post 2012-03-23 kendavies

require_once 'phplot.php';

Note: The font name used here is system-dependent.

define('DISCLAIMER_FONT', 'LiberationSans-Italic');

Text to display:

define('STD_DISCLAIMER',
"This plot is not the proprietary information of anybody in particular.
©2012 Nobody Owns This
Unauthorized use and reproduction is encouraged, but pointless.");

Function to draw text on the plot:

Note: You can instead use PHP/GD's imagestring() or imagettftext() to draw

your text. This example uses PHPlots (semi-internal) DrawText(), which

has advantages such as being able to align the text horizontally.

The first argument '' means use PHPlot's "generic" font setting.

function annotate($img, $plot)
{
$text_color = imagecolorresolve($img, 0xff, 0x66, 0x66);
$plot->DrawText('', 0, 400, 595, $text_color, STD_DISCLAIMER,
'center', 'bottom');
}

$data = array(array('', 0, 0, 0), array('', 5, 10, 30));
$plot = new PHPlot(800, 600);
$plot->SetTitle('Plot With Annotation');
$plot->SetXTitle('This is the X Axis');
$plot->SetYTitle('This is the Y Axis');
$plot->SetDataType('data-data');
$plot->SetDataValues($data);
$plot->SetPlotType('lines');
$plot->SetPlotAreaWorld(0, 0);

Increase the bottom margin to leave room for our text:

$plot->SetMarginsPixels(NULL, NULL, NULL, 100);

Set an annotation callback, and pass it the PHPlot object:

$plot->SetCallback('draw_all', 'annotate', $plot);

Configure the Generic font, used by the callback:

$plot->SetFontTTF('generic', DISCLAIMER_FONT, 12);
$plot->DrawGraph();

~~~~~


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.