Making Chart In Php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

Making Chart In Php

Post by shafiq2626 »

Hi!
I have following code

Code: Select all

include("phpgraphlib.php"); 
$graph=new PHPGraphLib(500,350);
$data=array("Jan"=>5555,"Feb"=>44444,"Mar"=>3333,"Apr"=>333,"May"=>777,"Jun"=>22222,"Jul"=>2345,"Aug"=>5432,"Sep"=>21123,"Oct"=>3465,"Nov"=>55554,"Dec"=>333333);
 
//echo "<table align='center'><tr><td>";
 
$graph->addData($data);
$graph->setTitle("Month Wise Sales Position");
$graph->setGradient("red", "maroon");
$graph->setDataValues(true);
$graph->setDataValueColor("Blue");
$graph->createGraph();
If i past it in empty file then this is working good. But if i past this code in html table or in body then its not working. it shows garbage value and also show html tags.
please help with thanks
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Making Chart In Php

Post by pickle »

It sounds like this code is generating an image, and outputting that image directly. So to the browser, this code is essentially an image.

Try referring to it like an image, like so:

Code: Select all

<img src = "/path/to/the/file/with/this/code.php" alt = "Chart" />
Also, please wrap your code in [ code=php ][ /code ] tags so we can see syntax highlighting.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Making Chart In Php

Post by mikosiko »

But if i past this code in html table or in body then its not working.
maybe you are including this code without php tags?... I don't see any in the posted code
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

Re: Making Chart In Php

Post by shafiq2626 »

Code: Select all

<?php include("phpgraphlib.php"); 
$graph=new PHPGraphLib(500,350);
$data=array("Jan"=>$CatRecjan[0]['saleamount'],"Feb"=>$CatRecfeb[0]['saleamount'],"Mar"=>$CatRecmar[0]['saleamount'],"Apr"=>$CatRecapr[0]['saleamount'],"May"=>$CatRecmay[0]['saleamount'],"Jun"=>$CatRecjun[0]['saleamount'],"Jul"=>$CatRecjul[0]['saleamount'],"Aug"=>$CatRecaug[0]['saleamount'],"Sep"=>$CatRecsep[0]['saleamount'],"Oct"=>$CatRecoct[0]['saleamount'],"Nov"=>$CatRecnov[0]['saleamount'],"Dec"=>$CatRecdec[0]['saleamount']);
$graph->addData($data);
$graph->setTitle("Month Wise Sales Position");
$graph->setGradient("red", "maroon");
$graph->setDataValues(true);
$graph->setDataValueColor("Blue");
$graph->createGraph();
?>
I wrote php tag if i wrote above code in a file without using html tags or table then this is working properly but if i wrot it in tags like

Code: Select all

<html>
<body>
<tr><td>
<?php include("phpgraphlib.php"); 
$graph=new PHPGraphLib(500,350);
$data=array("Jan"=>$CatRecjan[0]['saleamount'],"Feb"=>$CatRecfeb[0]['saleamount'],"Mar"=>$CatRecmar[0]['saleamount'],"Apr"=>$CatRecapr[0]['saleamount'],"May"=>$CatRecmay[0]['saleamount'],"Jun"=>$CatRecjun[0]['saleamount'],"Jul"=>$CatRecjul[0]['saleamount'],"Aug"=>$CatRecaug[0]['saleamount'],"Sep"=>$CatRecsep[0]['saleamount'],"Oct"=>$CatRecoct[0]['saleamount'],"Nov"=>$CatRecnov[0]['saleamount'],"Dec"=>$CatRecdec[0]['saleamount']);
$graph->addData($data);
$graph->setTitle("Month Wise Sales Position");
$graph->setGradient("red", "maroon");
$graph->setDataValues(true);
$graph->setDataValueColor("Blue");
$graph->createGraph();
?>
</td></tr>
<table>
</table>
</body>
</html>
this is not working properly making garbage value and in mozill gave error
but with out html tags working properly in bothe explorer.
please help
Post Reply