Page 1 of 1
Making Chart In Php
Posted: Thu Mar 11, 2010 5:10 am
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
Re: Making Chart In Php
Posted: Thu Mar 11, 2010 9:57 am
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.
Re: Making Chart In Php
Posted: Thu Mar 11, 2010 12:23 pm
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
Re: Making Chart In Php
Posted: Fri Mar 12, 2010 1:03 am
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