CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Wishes

 Howto use jpgraph to plot results in ccs

Print topic Send  topic

Author Message
sibawe

Posts: 4
Posted: 06/15/2007, 5:58 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

Sibawe


View profile  Send private message
sibawe

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

Sorry, this was not posted in the right place ... :-/

Please add your comments here: http://forums.codecharge.com/posts.php?post_id=88344
View profile  Send private message
Benjamin Krajmalnik
Posted: 06/18/2007, 6:02 PM

Hi Sibawe,

I use a totaly different technique, which I have made easier by using some
classes which we developed uniformly aroung jpGraph and the InfosoftGobal
graphics plugins. The technique is simple - instead of creating the graphs
"inline" (wjhich require writing to disk so they can be read) we simple use
an object within the html to generate the graph. The graph is essentially
generated asynchronously.

In the case of jpGraph, our wrapper creates an image tag. <img
src="mygraphgenerator.xxx">
mygraphgenerator.xxx can be any script in any language (even on another
website if need be!) which generates the graph. Since it is dished
asynchronoulsy by a separate call, you do not have the problem of it bieng
parsed properly by the template parser.


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.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


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