CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 howto use jpgraph to plot results in ccs (2)

Print topic Send  topic

Author Message
sibawe

Posts: 4
Posted: 06/15/2007, 6:02 PM

Hi,

This is an outline procedure on how to use jpgraph in ccs.

Here's basically what you'll be doing: create a jpgraph object, feed data into it, generate the graph's image file (i.e. gif, png format) and store it on disk. Then, you'll use a ccs label to retrieve the image file and plug it into your project.

This solution is pretty fast. However, you'll need write privileges on the web server disk ( => to store the images) and you'll need to think of some way to clean the disk when the images are no longer needed ( => ex: some cron that will delete any file older than x days). True, this is not the elegant part of the procedure...

In my case, I have a questionnaire that collects data and makes it available for a report page called by the user, that shows him the results graphically. My graph is a "radar".

Let's go:

1/ unzip the jpgraph directory in the web directory where you publish your project (not in the project directory itself, since ccs won't publish the jpgraph directory for you)
2/ attach a "AfterExecuteInsert" event to the questionnaire
3/ select custom code and create the jpgraph object:

require_once ("jpgraph-2.2/src/jpgraph.php");
require_once ("jpgraph-2.2/src/jpgraph_radar.php");

// Create the basic rtadar graph
$radar = new RadarGraph(400,400,"auto");

// Set background color and shadow
$radar->SetColor("#FCF9F0");
$radar->SetShadow();

// Position the graph
$radar->SetCenter(0.5,0.5);

// Setup the axis formatting
$radar->axis->SetFont(FF_FONT1,FS_BOLD);
$radar->axis->SetWeight(2);

// Setup the grid lines
$radar->grid->SetLineStyle("longdashed");
$radar->grid->SetColor("navy");
$radar->grid->Show();
$radar->HideTickMarks();

// Setup graph titles
$radar->title->Set("Schéma global");
$radar->title->SetFont(FF_FONT2,FS_BOLD);
$radar->SetTitles(array("Stat1","Stat2","Stat3","Stat4","Stat5"));

4/ Retrieve the database values that you'll feed into the object. In my case, all data is first inserted into the database, with an id tag, then retrieved. you'll need to adapt to your settings

// retrieve id

global $DB;
$Page = CCGetParentPage($sender);
$id=CCGetFromGet("id","");

// Retrieve data for the graph
$Stat1 = CCDLookup("Stat1","resul","id=$id",$DB);
$Stat2 = CCDLookup("Stat2","resul","id=$id",$DB);
...

5/ Create the plot and save to the destination directory. In my case, I have a directory called "radar" and I store png files named after the id tags mentionned above

// Create the radar plot
$plot= new RadarPlot(array($Stat1,$Stat2,$Stat3,$Stat4,$Stat5));
$plot->SetLegend("Your results");
$plot->SetColor("red","lightred");

// Add the plots to the graph
$radar->Add($plot);

// And output the graph
$destination="radars/".$id.".radar.png";
$radar->Stroke($destination);


6/ That's it for the questionnaire, Now open the report form, add a label

7/ Attach a "BeforeSet" event to the label
8/ select custom code and write the following

$id=CCGetFromGet("id", "");
$text_html="<img src=\"radars/$id.radar.png\" border=\"0\" >";
$Component->setvalue($text_html);

9/ In the label's properties, put Data->content to HTML

10/ that's it

Good luck



PS : intially posted in the wrong place .(wishes... :-/)
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.