La première chose à faire est d'inclure les
fichiers de classes :
We have to include the class files :
// Include the class files.
define('PHP4SVG_INCLUDE_PATH', '../Php4Svg/');
require_once "Php4Svg.inc.php";
Ensuite, nous créons le document racine, nous lui
donnons un titre et une description :
Now, we can create the document root and we give it a title
and a description :
// Le document
$svg =& new Php4SvgDocument('300', '100');
$titre =& new Php4SvgTitle('Un rectangle');
$desc =& new Php4SvgDesc('Mon premier graphique avec Php4Svg');
$svg->AddTitle($titre);
$svg->AddDesc($desc);
Nous définissons un groupe qui va contenir notre rectangle,
nous lui donnons un identifiant, le premier paramètre
du constructeur de la classe.
// Build a group and set the style.
$g0 =& new Php4SvgGroup('group', 'fill:grey; stroke:black');
// Add a parent to the g instance.
$svg->AddChild( $g0);
Nous dessinons le rectangle :
// Drawing a rectangle
$rect =& new Php4SvgRect('250', '80', '25', '10');
$g0->AddChild($rect);
Et nous envoyons le résultat vers le navigateur :
// Output the SVG to the viewer
$svg->OutputSVGToViewer();
Voilà le code dans son intégralité :
Here is the full code of this example :
<?php
// Include the class files.
define('PHP4SVG_INCLUDE_PATH', '../Php4Svg/');
require_once "Php4Svg.inc.php";
$svg =& new Php4SvgDocument( "300", "100");
$titre =& new Php4SvgTitle('Un rectangle');
$desc =& new Php4SvgDesc('Mon premier graphique avec Php4Svg');
$svg->AddTitle($titre);
$svg->AddDesc($desc);
// Build a group and set the style.
$g0 =& new Php4SvgGroup('group', 'fill:grey; stroke:black');
// Add a parent to the g instance.
$svg->AddChild( $g0);
// Drawing a rectangle
$rect =& new Php4SvgRect('250', '80', '25', '10');
$g0->AddChild($rect);
// Output the SVG to the viewer
$svg->OutputSVGToViewer();
?>