Documentation:

Back
phpchartPlus Documentation
Tsiavos Chris <[email protected]>
Date: 18-Feb-2005
License: GPL
3.2.2 Using the XMLData Strategy
requires SimpleXML Extension
To use the XMLData Strategy you have to follow 4 steps
1. Include the appropriate file
2. Initialize the XMLData Strategy class
3. Strategize the DataParser instance with the XMLData Strategy instance
4. Pass the filename of the xml data file as a parameter to the strategized DataParser instance
code portion from file: "Examples/example.php"
include("../Sources/phpchartPlus.php");
include("../Sources/CacheToPEARDB_Strategy.php");

include("../Sources/XMLData_Strategy.php");
include("../Sources/PHPConfig_Strategy.php");

$CacheParams=array("DB_Type"=>"",
"DB_Username"=>"",
"DB_Passwd"=>"",
"DB_Host"=>"",
"DB_Name"=>"",
"DB_Table"=>"",
"Field_ImageName"=>"",
"Field_ImageData"=>"",
"Field_ImageModification"=>"");


$DataParams=array("filename"=>"../Data/ChartData.xml");

$ConfigParams=array("ImageWidth"=>420,
"ImageHeight"=>300,
"ImageOutputType"=>"png",
"ChartTitle"=>"Web Servers Usage",
"ChartType"=>"Area",
"ChartUseBlending"=>"Yes",
"ChartUseAntialias"=>"Yes",
"ChartHmargin"=>30,
"ChartVmargin"=>25,
"ChartUseStatus"=>"Yes", "ChartBgImage"=>"../Data/bgimage.png",
"ImageColor_Start"=>"DimGray",
"ImageColor_Finish"=>"DimGray",
"ImageColor_Alpha"=>70,
"ChartColor_Start"=>"DimGray",
"ChartColor_Finish"=>"FloralWhite",
"ChartColor_Alpha"=>50,
"FontColor"=>"White",
"FontWidth"=>3,
"FontHeight"=>3,
"LegendColors"=> array("DarkRed,Yellow","Black,DarkGreen"),
"LegendColors_Alpha"=>array(30,60),
"GridNum"=>4,
"GridMinValue"=>0,
"GridMaxValue"=>100,
"GridColor"=>"Black");

$DataStrategy=new XMLData_Strategy();
$ConfigStrategy=new PHPConfig_Strategy();
$CacheStrategy=new CacheToPEARDB_Strategy();
 $im=new phpchartPlus();
                   
try
   {
     $im->DataParser_->strategize($DataStrategy,$DataParams);
     $im->DataParser_->parse();
   }
   catch (DataParser_Exception $e) 
   {
     print $e->getMessage();
     exit();
   }
   catch (DataStrategy_Exception $f) 
   {
     print $f->getMessage();
     exit();
   }
try
   {
     $im->ConfigParser_->strategize($ConfigStrategy);
     $im->ConfigParser_->parse($ConfigParams);
   }
   catch (ConfigParser_Exception $e) 
   {
     print $e->getMessage();
     exit();
   }
   catch (ConfigStrategy_Exception $f) 
   {
     print $f->getMessage();
     exit();
   } 
   
try
   {
     $im->get_Instance();
   }
   catch (ImageSupport_Exception $e)
   {
     print $e->getMessage();
     exit();
   }
   catch (FontSupport_Exception $f)
   {
     print $f->getMessage();
     exit();
   }
   
try
{
$im->Chart_->set_CachingStrategy($CacheStrategy,2,$CacheParams); 
//Cache for 2 minutes
}
catch (CachingStrategy_Exception $e)
{
  print $e->getMessage();
  exit();
}
   
$im->Chart_->draw_Chart(); 

 
The XML data file must be valid against the following DTD:
<!ELEMENT groups (group+) >
<!ELEMENT group (item+) >
<!ELEMENT item (name,value) >
<!ELEMENT name (#PCDATA) >
<!ELEMENT value (#PCDATA) >
<!ATTLIST group name CDATA #REQUIRED > 
 

 
Hosted by www.Geocities.ws

1