hello,
i want my program to have the ability to generate a graph from the existing data. it works well.
but i want there's a block of text that describe the generated graph or maybe to have a link or button in the same page with the graph.

i read in some article that i cant adding some text in the graph file, and he said to use

<img src= >

as the solution.
i already tried using

<img src= >

but it only gives me a broken image :(

but if i call the graph.php only, it working really well..
i am using JpGraph.


anyone have an idea of that ?
thanks :)

Hmm I would need to see your code, also does JpGraph create a jpeg of the graph on the server? If that is the case, then the src= would just be a path to the created jpeg. If this is the case, then have the graph show in a div, that is hidden by default, the have a button linked to a javascript function that shows the div.

Have you though about using a flash graph generator such as fusion, they are really good, and take XML as the data, along with loads of options to style, only problem they are not free, and of course they are flash which you normally want to avoid.

Hope this helps :)

waaw fusion makes me drooling :*, but i want a free one :$

actually i am still a newbie in php programming :$
i dont know whether it creates the jpeg file on the server, but i think it is hidden (by default). because i cant find the generated image on the htdocs folder :(

ah and here goes my code, i am doing this based on a tutorial on a website :)

<img src="grafik_bar.php?sped=<?$match?>">

and this is my jpgraph code

<?
//solusi pertama -> result disimpen di xml -> tiap ngerewrite di load aj biar data yang 
//lama gak ilang
//include_path = C:\xampp\htdocs;
//include ('C:\xampp\htdocs\new_3jan.php');
include ('C:\xampp\htdocs\jpgraph-3.5.0b1\src\jpgraph.php');
include ('C:\xampp\htdocs\jpgraph-3.5.0b1\src\jpgraph_bar.php');
include ('C:\xampp\htdocs\jpgraph-3.5.0b1\src\en.inc.php');

ob_clean();
ob_end_clean();

//echo $mp . "<br>" . "<br>" ;
//$panjanggrafik=($mp*$count)/100;
$x=$_GET['sped'];
//ntar disini $mp dijadiin array yang nyimpen hasil match dari banyak produk :D

$graph = new Graph(450,200,"auto");
$graph->SetScale("textlin");

$splot = new BarPlot($x);
$splot->SetFillColor("blue");
$splot->value->show();
$splot->SetLegend("Spreadrum G189");

$graph->img->SetMargin(40,110,20,40);
$graph->title->Set("Product Comparison Graph");
$graph->xaxis->title->Set("Product");
$graph->yaxis->title->Set("Match Percentage");
$graph->xaxis->SetTickLabels($x);

$graph->Add($splot);
//menampilkan image ke browser
$graph->Stroke();
?>

or maybe you have another solution for my problem?
the point is i want to generate a graph which contain comparasion values. and i want to show the product (that has the highest value )specifications below the showed graph :).
i tried to find tutorial on the web, but it useless :(
thankyou so much :)

This should push the result into an image on the web server for later use. One thing to note, you might want to do something more complicated to determine the filename, such as random number or something like that, as this will overwrite the file with the same name.

Once the image of the graph is on your web server you can then use javascript functions to show, hide or do whatever with as it would be a standard image.

$graph = new Graph(400,300);
 
// ... code to generate a graph ...
 
// Get the handler to prevent the library from sending the
// image to the browser
$gdImgHandler = $graph->Stroke(_IMG_HANDLER);
 
// Stroke image to a file and browser
 
// Default is PNG so use ".png" as suffix
$fileName = "/tmp/imagefile.png";
$graph->img->Stream($fileName);
 
// Send it back to browser
$graph->img->Headers();
$graph->img->Stream();

Also from your code, I have noticed that your not actually out puting your graph, you need to use the Stream() function in order to display.

hei, i tried the code that you told me. but everytime i ran it, it always gives me error message :(
at first they said that fatal error cannot redeclare function on my main php file. i already solved the problem by adding some condition.

here's my main code

<html>
<?
//bikin radio button buat milih nama file produk yang mau di compare
error_reporting(E_ALL ^ E_NOTICE); // di solved nanti
$xml1="spreadrum_g189.xml";
$xml2="xml_softspec.xml";
$xml3="mtk_p800_1.xml";
$xml4="mtk_e710.xml";

$dom1= new DOMDocument;
$dom1->load($xml1); 
$dom1->formatOutput=true;
$dom1->preserveWhiteSpace = false;
$dom1->normalizeDocument();

$dom2= new DOMDocument;
$dom2->load($xml2);
$dom2->formatOutput=true;
$dom2->preserveWhiteSpace = false;
$dom2->normalizeDocument();

$dom3= new DOMDocument;
$dom3->load($xml3); 
$dom3->formatOutput=true;
$dom3->preserveWhiteSpace = false;
$dom3->normalizeDocument();

$dom4= new DOMDocument;
$dom4->load($xml4); 
$dom4->formatOutput=true;
$dom4->preserveWhiteSpace = false;
$dom4->normalizeDocument();

$sspec1=$dom1->getElementsByTagName("soft_spec")->item('0');
$sspec1->normalize();
$sspec2=$dom2->getElementsByTagName("soft_spec")->item('0');
$sspec2->normalize();
$sspec3=$dom3->getElementsByTagName("soft_spec")->item('0');
$sspec3->normalize();

$node=0;
$node1=0;
$match=0;
$unmatch=0;
$mp=0; 
$count=0; 
$countdb=0;

if(!function_exists('hasChild')){
function hasChild($hc){
    if (($hc != null) && $hc->hasChildNodes()){
		foreach ($hc->childNodes as $c)
		{
		if ($c->nodeType == XML_ELEMENT_NODE)
		return true;
		};
    }
    return false;
};
};

//ntar functionnta dimasukin di function.php aja :p
if(!function_exists('shownode')){
function shownode($x){
		foreach($x->childNodes as $p){
		if (hasChild($p)){
			echo $p->nodeName . " ->HAS CHILD <br> ";
			shownode($p);
			} elseif ($p->nodeType == XML_ELEMENT_NODE)
			echo $p->nodeName . " " . $p->nodeValue . '<br>';
		};
};};

include "child1.php";
include "sub_child12.php";
/* foreach ($child_2 as $x)
echo $x;	 */
include "ret_dbdata.php";
include "ret_reqdata.php";
include "ret_dbmtk.php"; 
include "ret_mtke.php"; //lsg dr dom2, jd tergantng req.dirombak aj dr awal ambl pny sndiri
include "matching_child1.php";
include "matching_child_mtk.php";
include "matching_child_mtke710.php";
include "count_sped.php"; //
include "saving_result.php";
//ntar hasil match disimpen di array aja klo mau compare banyak.. 
//echo $countdb. "<br>";
echo "Total Requirement : " . $count ."<br>";
echo "Spreadrum Match   : " . $match_sped ."<br>";
echo "Mtk P800 Match    : " . $match_mtk ."<br>";
echo "Mtk P710 Match    : " . $match_mtke ."<br>";
echo "Total Product Specification Spreadrum: " . $count_sped ."<br>";
echo "Total Product Specification MTK P800: " . $count_mtk ."<br>";
echo "Total Product Specification MTK E710: " . $count_mtke ."<br>";

if($match > $count){
echo "Invalid Input... <br>";
echo "Please Try again";
//masukin button back yang redirect ke tempat input
//masukin add another requirement.
}
else{
$mp_sped=($match_sped/$count_sped)*100;
$mp_mtk=($match_mtk/$count_mtk)*100;
$mp_mtke=($match_mtke/$count_mtke)*100;
};
include "grafik_bar.php";
echo "<br>" . "<br>";
echo " Total Match Percentage Spreadrum G189	: " . $mp_sped . "%" . "<br>";
echo " Total Match Percentage MTK P800   		: " . $mp_mtk . "%" . "<br>";
echo " Total Match Percentage MTK E710   		: " . $mp_mtke . "%";
include "grafik_bar.php";

//<img src="grafik_bar.php?sped=<?$match?/>/> 
?>

</html>

and here my graph code

<?
//solusi pertama -> result disimpen di xml -> tiap ngerewrite di load aj biar data yang 
//lama gak ilang
//include_path = C:\xampp\htdocs;
//include ('C:\xampp\htdocs\new_3jan.php');
include ('C:\xampp\htdocs\jpgraph-3.5.0b1\src\jpgraph.php');
include ('C:\xampp\htdocs\jpgraph-3.5.0b1\src\jpgraph_bar.php');
include ('C:\xampp\htdocs\jpgraph-3.5.0b1\src\en.inc.php');

ob_clean();
ob_end_clean();

//echo $mp . "<br>" . "<br>" ;
//$panjanggrafik=($mp*$count)/100;

include 'new_8jan.php';
if (isset($_GET['mp_sped'])&&isset($_GET['$mp_mtk'])&&isset($_GET['$mp_mtke'])){
	$ysped=$_GET['$mp_sped'];
	$ymtk=$_GET['$mp_mtk'];
	$ymtke=$_GET['$mp_mtke'];
};
//ntar disini $mp dijadiin array yang nyimpen hasil match dari banyak produk :D

$graph = new Graph(450,200,"auto");
$graph->SetScale("textlin");

$splot = new BarPlot($ysped);
$splot->SetFillColor("red");
$splot->value->show();
$splot->SetLegend("Spreadrum G189");

$mpplot = new BarPlot($ymtk);
$mpplot->SetFillColor("green");
$mpplot->value->show();
$mpplot->SetLegend("MTK P800");

$meplot = new BarPlot($ymtke);
$meplot->SetFillColor("blue");
$meplot->value->show();
$meplot->SetLegend("MTK E710");

$graph->Add($splot,$mpplot,$meplot);
$graph->title->Set("Product Comparison Graph");
$graph->xaxis->title->Set("Product");
$graph->yaxis->title->Set("Match Percentage");
$graph->xaxis->SetTickLabels(100);

$meplot->img->SetMargin(40,110,20,40);
$gdImgHandler=$graph->Stroke(_IMG_HANDLER);

//stroke image to a file and browser.
$graph->Stroke();

$fileName="/tmp/imagefile.png";
$graph->img->Stream('$fileName');

//send it back to the browser
$graph->img->Headers();
$graph->img->Stream();
?>

this the error that showed

Fatal error: Cannot redeclare CheckPHPVersion() (previously declared in C:\xampp\htdocs\jpgraph-3.5.0b1\src\jpgraph.php:230) in C:\xampp\htdocs\jpgraph-3.5.0b1\src\jpgraph.php on line 242

do you have an idea?
and after i solved this, i would be able to show the graph like i try to show standart image file? ":)
thankyou :)

hey, i solved the problem :D
i am sorry for the inconvenience :(
but still the text that i wrote before, didn't showed because of the graph. :(
heres my graph code

<?
include ('C:\xampp\htdocs\jpgraph-3.5.0b1\src\jpgraph.php');
include ('C:\xampp\htdocs\jpgraph-3.5.0b1\src\jpgraph_bar.php');
include ('C:\xampp\htdocs\jpgraph-3.5.0b1\src\en.inc.php');

ob_clean();
ob_end_clean();

//echo $mp . "<br>" . "<br>" ;
//$panjanggrafik=($mp*$count)/100;

//include 'new_8jan.php';

if (isset($mp_sped)&&isset($mp_mtk)&&isset($mp_mtke)){
	$ysped=$mp_sped;
	$ymtk=$mp_mtk;
	$ymtke=$mp_mtke;
};
//ntar disini $mp dijadiin array yang nyimpen hasil match dari banyak produk :D

$graph = new Graph(450,200,"auto");
$graph->SetScale("textlin");

$splot = new BarPlot($ysped);
$splot->SetFillColor("red");
$splot->value->show();
$splot->SetLegend("Spreadrum G189");

$mpplot = new BarPlot($ymtk);
$mpplot->SetFillColor("green");
$mpplot->value->show();
$mpplot->SetLegend("MTK P800");

$meplot = new BarPlot($ymtke);
$meplot->SetFillColor("blue");
$meplot->value->show();
$meplot->SetLegend("MTK E710");
//$meplot->img->SetMargin(40,110,20,40);
$graph->Add($splot,$mpplot,$meplot);
$graph->title->Set("Product Comparison Graph");
$graph->xaxis->title->Set("Product");
$graph->yaxis->title->Set("Match Percentage");
$graph->xaxis->SetTickLabels(100);


$gdImgHandler=$graph->Stroke(_IMG_HANDLER);

//stroke image to a file and browser.
$graph->Stroke();

$fileName="/tmp/imagefile.png";
$graph->img->Stream('$fileName');

//send it back to the browser
$graph->img->Headers();
$graph->img->Stream();
?>

thankyou

Have you made sure that '/tmp/' exists and your apache has the permissions to write to the folder? Also if your writing the output to an image, the lines after $graph->img->Stream('$fileName'); would not be needed.

At the end of the PHP have this line just to test, <img src='/tmp/imagefile.png'>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.