Sending values to JpGraph using PHP

10-29-09, 11:53 AM
|
|
Newbie Coder
|
|
Join Date: Oct 2009
Posts: 8
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
|
Sending values to JpGraph using PHP
Hi!
I was wondering on how I can send values through php so that JpGraph would take them to plot graphs?
Thanks
Last edited by dandiud; 10-29-09 at 12:02 PM.
|

10-29-09, 09:10 PM
|
 |
Level II Curmudgeon
|
|
Join Date: Dec 2004
Posts: 2,838
Thanks: 13
Thanked 11 Times in 10 Posts
|
|
This is an example that uses JPGraph:
PHP Code:
require_once("jpgraph.php");
require_once("jpgraph_bar.php");
// example - fill array 'databary2' with 12 values, one for each month
$databary2[] = '23';
$databary2[] = '34';
$databary2[] = '92';
$databary2[] = '71';
$databary2[] = '15';
$databary2[] = '16';
$databary2[] = '45';
$databary2[] = '66';
$databary2[] = '8';
$databary2[] = '69';
$datax=array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
// New graph with a drop shadow
$graph = new Graph($xdim,$ydim,"auto");
$graph->SetScale("textlin");
$graph->SetShadow();
// left,right,top,bottom
$graph->img->SetMargin(40,30,20,60);
// Create the bar plots
//$b1plot = new BarPlot($databary1);
//$b1plot->SetFillColor($gcolor1);
$b2plot = new BarPlot($databary2);
$b2plot->SetFillColor($gcolor2);
//$b1plot->SetLegend("Scheduled");
$b2plot->SetLegend("Actual");
if ($useLabels == "on"){
//$b1plot->value->SetFormat('%d');
//$b1plot->value->Show();
$b2plot->value->SetFormat('%d');
$b2plot->value->Show();
// set y-grace
$graph->yaxis->scale->SetGrace(6,auto);
}else{
$graph->yaxis->scale->SetGrace(3,auto);
}
// add the credit line if graph is big enough
if($xdim > 300){
$txt =new Text("SomeSite.com");
$pos1 = ($xdim - 120);
$pos2 = ($ydim - 22);
$txt->Pos( $pos1,$pos2);
$txt->SetColor( "black");
$graph->AddText( $txt);
}
// use a bar shadow if set
if ($shadow == "on"){
// $b1plot->SetShadow($aShadowColor,$aShadowWidth);
$b2plot->SetShadow($aShadowColor,$aShadowWidth);
}
$graph->legend->SetAbsPos($xlabel,$ylabel,'left','bottom');
$graph->legend->SetColumns(3);
$graph->legend->SetFont(FF_FONT1,FS_NORMAL,14);
$graph->legend->SetFillColor('#ffffff');
// Setup month on X-scale
$graph->xaxis->SetTickLabels($datax);
// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot));
// ...and add it to the graPH
$graph->Add($gbplot);
// Set title and subtitle
$graph->title->Set("$statYear - Legend For Sample Graph");
$graph->xaxis->title->Set("Month");
$graph->yaxis->title->Set("Days with Contact");
if($xdim > 400){
$graph->title->SetFont(FF_FONT2,FS_BOLD);
}else{
$graph->title->SetFont(FF_FONT1,FS_BOLD);
}
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
// Finally output the image
$graph->Stroke();
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data (scroll down)
|
|
The Following User Says Thank You to End User For This Useful Post:
|
|

11-02-09, 11:35 PM
|
|
Newbie Coder
|
|
Join Date: Oct 2009
Posts: 8
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Thanks?
Anyway I could send that through a variable? (example.php?value1=[etc...]&value2=[...]
???
|

11-03-09, 08:35 AM
|
 |
Community Liaison
|
|
Join Date: Jul 2007
Location: Michigan, USA
Posts: 305
Thanks: 1
Thanked 4 Times in 4 Posts
|
|
Just a quick modifcation of End User's code, but receiving data from within the URL, this should work. (I only modified how the array is being populated).
PHP Code:
require_once("jpgraph.php");
require_once("jpgraph_bar.php");
// example - fill array 'databary2' with 12 values, one for each month
$databary2[] = $_GET['value1'];
$databary2[] = $_GET['value2'];
$databary2[] = $_GET['value3'];
$databary2[] = $_GET['value4'];
$databary2[] = $_GET['value5'];
$databary2[] = $_GET['value6'];
$databary2[] = $_GET['value7'];
$databary2[] = $_GET['value8'];
$databary2[] = $_GET['value9'];
$databary2[] = $_GET['value10'];
$databary2[] = $_GET['value11'];
$databary2[] = $_GET['value12'];
$datax=array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
// New graph with a drop shadow
$graph = new Graph($xdim,$ydim,"auto");
$graph->SetScale("textlin");
$graph->SetShadow();
// left,right,top,bottom
$graph->img->SetMargin(40,30,20,60);
// Create the bar plots
//$b1plot = new BarPlot($databary1);
//$b1plot->SetFillColor($gcolor1);
$b2plot = new BarPlot($databary2);
$b2plot->SetFillColor($gcolor2);
//$b1plot->SetLegend("Scheduled");
$b2plot->SetLegend("Actual");
if ($useLabels == "on"){
//$b1plot->value->SetFormat('%d');
//$b1plot->value->Show();
$b2plot->value->SetFormat('%d');
$b2plot->value->Show();
// set y-grace
$graph->yaxis->scale->SetGrace(6,auto);
}else{
$graph->yaxis->scale->SetGrace(3,auto);
}
// add the credit line if graph is big enough
if($xdim > 300){
$txt =new Text("SomeSite.com");
$pos1 = ($xdim - 120);
$pos2 = ($ydim - 22);
$txt->Pos( $pos1,$pos2);
$txt->SetColor( "black");
$graph->AddText( $txt);
}
// use a bar shadow if set
if ($shadow == "on"){
// $b1plot->SetShadow($aShadowColor,$aShadowWidth);
$b2plot->SetShadow($aShadowColor,$aShadowWidth);
}
$graph->legend->SetAbsPos($xlabel,$ylabel,'left','bottom');
$graph->legend->SetColumns(3);
$graph->legend->SetFont(FF_FONT1,FS_NORMAL,14);
$graph->legend->SetFillColor('#ffffff');
// Setup month on X-scale
$graph->xaxis->SetTickLabels($datax);
// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot));
// ...and add it to the graPH
$graph->Add($gbplot);
// Set title and subtitle
$graph->title->Set("$statYear - Legend For Sample Graph");
$graph->xaxis->title->Set("Month");
$graph->yaxis->title->Set("Days with Contact");
if($xdim > 400){
$graph->title->SetFont(FF_FONT2,FS_BOLD);
}else{
$graph->title->SetFont(FF_FONT1,FS_BOLD);
}
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
// Finally output the image
$graph->Stroke();
|

11-03-09, 08:39 AM
|
 |
Level II Curmudgeon
|
|
Join Date: Dec 2004
Posts: 2,838
Thanks: 13
Thanked 11 Times in 10 Posts
|
|
Quote:
Originally Posted by dandiud
Anyway I could send that through a variable? (example.php?value1=[etc...]&value2=[...]
|
Sure, I do it all the time to pass other parameters like color, shadow status, etc.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data (scroll down)
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|