Current location: Hot Scripts Forums » Programming Languages » PHP » Displaying JPGraph with text below graph


Displaying JPGraph with text below graph

Reply
  #1 (permalink)  
Old 01-13-04, 02:54 PM
smombour smombour is offline
New Member
 
Join Date: Jan 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Displaying JPGraph with text below graph

Hi,
I need some help. I need to be able to display my graph with text above and below the actual PHP graph.
http://132.156.178.22/stephweb/php/stephanie.php

I tried even printing a simple "Hello World" string, but it seems as if the script stops after the Stroke();

Is there an easy way to do this?

Can anyone help me?

Thanks,
Stephanie


My Code

<?php
include ("../jpgraph.php");
include ("../jpgraph_bar.php");

$data1y=array(12,8,19); // house
$data2y=array(8,2,11); // potential

// Create the graph. These two calls are always required
$graph = new Graph(400,300,"auto"); //(length, height)
$graph->SetScale("textlin",0,35);

$graph->yscale->ticks->Set(35,10);
$graph->yaxis->SetColor("lightblue");

$graph->SetMarginColor("lightblue");
$a = array("Heating\nConsumption","Cooling\nConsumption ","Hot Water Tank\nConsumption");

$graph->xaxis->SetLabelAlign('center');
$graph->xaxis->SetTickLabels($a);
$graph->xaxis->SetFont(FF_ARIAL);
$graph->SetShadow();
$graph->img->SetMargin(40,30,20,80);

// Create the bar plots
$b1plot = new BarPlot($data1y);
$b1plot->SetFillColor("midnightblue");
$b1plot->SetLegend("Your House");

$b2plot = new BarPlot($data2y);
$b2plot->SetFillColor("steelblue3");
$b2plot->SetLegend("Your Potential");

$gbplot = new GroupBarPlot(array($b1plot,$b2plot));
$gbplot->SetWidth(0.7);

// ...and add it to the graPH
$graph->Add($gbplot);

$graph->title->SetFont(FF_ARIAL,FS_BOLD,20);
$graph->yaxis->title->SetFont(FF_ARIAL,FS_BOLD);
$graph->xaxis->title->SetFont(FF_ARIAL,FS_BOLD);

$graph->title->Set("Energy Consumption");
$graph->yaxis->title->Set("Energy");

// Display the graph
$graph->Stroke();

print("Hello<br>");
?>
Reply With Quote
  #2 (permalink)  
Old 02-05-04, 12:30 PM
bryan bryan is offline
New Member
 
Join Date: Feb 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
I have the same question

Did you ever get an answer to this? I sure would like to know how to do this, too.
Reply With Quote
  #3 (permalink)  
Old 02-09-04, 09:46 AM
smombour smombour is offline
New Member
 
Join Date: Jan 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by bryan
Did you ever get an answer to this? I sure would like to know how to do this, too.
No I didn't, and I have to figure it out soon...
Reply With Quote
  #4 (permalink)  
Old 02-09-04, 11:04 AM
websalacarta websalacarta is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Spain
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
why donīt you try with GD?

http://es.php.net/manual/en/function.imagettftext.php

Code:
<?php
  header("Content-type: image/jpeg");
  $im = imagecreate(400, 30);
  $white = imagecolorallocate($im, 255, 255, 255);
  $black = imagecolorallocate($im, 0, 0, 0);
 
  // Replace path by your own font path
  imagettftext($im, 20, 0, 10, 20, $black, "/path/arial.ttf",
  "Testing... Omega: &amp;#937;");
  imagejpeg($im);
  imagedestroy($im);
?>
Reply With Quote
  #5 (permalink)  
Old 02-02-06, 02:41 PM
astro_dave astro_dave is offline
New Member
 
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Smile little more than 2 years later...

Hi Stephanie, I wonder if you ever figured it out.

As i understand it you want your image to appear on the page, and to then be able to write text on the page afterwards.

This is not possible in the way you tried as the "headers have already been sent". Basically you can't have a php page that generates a JPGraph and then add text ans stuff to that page.

A quick way around this is to have the JPGraph php code that produces your graph in one page, e.g. linegraph.php and then to have another page, e.g. index.html or index.php that calls the linegraph.php:
<td><img src="linegraph.php" name="line graph"/></td>
When the index.php page is loaded, linegraph.php will be executed and the resulting image will be displayed on the image.php page.

You are free to put allsorts on your main.php page - images, text, everything.

Let me know if this was of any use.

astro_dave
Reply With Quote
Reply

Bookmarks


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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
text area and hyperlinking aparna PHP 3 01-02-04 01:37 AM
== cheap text advertisements == geesh General Advertisements 1 12-21-03 12:00 AM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM
Editing a text file. cjh_60 PHP 1 10-14-03 03:59 PM
displaying all duplicate records in my table. dsumpter PHP 6 09-02-03 10:54 AM


All times are GMT -5. The time now is 08:29 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.