Current location: Hot Scripts Forums » Programming Languages » PHP » Sending values to JpGraph using PHP

Sending values to JpGraph using PHP

Reply
  #1  
Old 10-29-09, 11:53 AM
dandiud dandiud is offline
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.
Reply With Quote
  #2  
Old 10-29-09, 09:10 PM
End User's Avatar
End User End User is offline
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)
Reply With Quote
The Following User Says Thank You to End User For This Useful Post:
dandiud (10-30-09)
  #3  
Old 11-02-09, 11:35 PM
dandiud dandiud is offline
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=[...]

???
Reply With Quote
  #4  
Old 11-03-09, 08:35 AM
therocket954's Avatar
therocket954 therocket954 is offline
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(); 
__________________
--Eric Allison
Twitter: http://www.twitter.com/Eric_Allison
Reply With Quote
  #5  
Old 11-03-09, 08:39 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 2,838
Thanks: 13
Thanked 11 Times in 10 Posts
Quote:
Originally Posted by dandiud View Post
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)
Reply With Quote
Reply

Bookmarks

Tags
jpgraph, php


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] PHP file sending zoliky PHP 9 04-15-08 11:17 AM
[SOLVED] What needs to be done for sending SMS to Mobiles Using PHP suru_epn PHP 9 04-11-08 11:10 AM
Ajax....changing values of php variables sushi4664 JavaScript 1 08-09-07 01:04 AM
PHP Downside--Solutions? Amulet PHP 10 07-15-05 09:26 AM


All times are GMT -5. The time now is 09:00 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.2 (Unregistered)