Documentation:

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

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

$ConfigParams=array("ImageWidth"=>420,
"ImageHeight"=>300,
"ImageOutputType"=>"png",
"ChartTitle"=>"Web Servers Usage",
"ChartType"=>"Bar",
"ChartUseBlending"=>"Yes",
"ChartUseAntialias"=>"Yes",
"ChartHmargin"=>30,
"ChartVmargin"=>30,
"ChartUseStatus"=>"Yes",
"ImageColor_Start"=>"DimGray",
"ImageColor_Finish"=>"DimGray",
"ImageColor_Alpha"=>0,
"ChartColor_Start"=>"DimGray",
"ChartColor_Finish"=>"FloralWhite",
"ChartColor_Alpha"=>0,
"FontColor"=>"White",
"FontWidth"=>3,
"FontHeight"=>3,
"FontFileLocation"=>"../Fonts/ActionMan.ttf",
"FontSize"=>9,
"LegendColors"=> array("DarkRed,Yellow","Black,DarkGreen"),
"LegendColors_Alpha"=>array(0,0),
"GridNum"=>4,
"GridMinValue"=>0,
"GridMaxValue"=>100,
"GridColor"=>"Black");


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

$DataStrategy=new TXTData_Strategy();

$ConfigStrategy=new PHPConfig_Strategy();
$CacheStrategy=new NullCache_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();
   }
   
$im->Chart_->set_CachingStrategy($CacheStrategy); 
$im->Chart_->draw_Chart();
 
The TXT data file must have the following structure:
group0=groupname//item,value:item,value
group1=groupname//item,value:item,value
group2=groupname//item,value:item,value
 

 
Hosted by www.Geocities.ws

1