如何在jpgraph页面中嵌入php代码

时间:2012-09-17 08:31:52

标签: php javascript jquery html jpgraph

下面是我的jp图代码

            include_once ("jpgraph/jpgraph.php");
            include_once ("jpgraph/jpgraph_scatter.php");

            // Some data for the points
            $datax = array(3.5,13.7,3,4,6.2,6,3.5,8,14,8,11.1,13.7);
            $datay = array(10,22,12,13,17,20,16,19,30,31,40,43);

            // A new scatter graph
            $graph = new Graph(300,200,'auto');
            $graph->SetShadow();
            $graph->SetScale("linlin");

            //$graph->img->SetMargin(40,40,40,40);        

            $graph->title->Set("Scatter plot with Image Map");
            $graph->title->SetFont(FF_FONT1,FS_BOLD);

            // Client side image map targets
            $targ=array("pie_csimex1.php#1","pie_csimex1.php#2","pie_csimex1.php#3",
            "pie_csimex1.php#4","pie_csimex1.php#5","pie_csimex1.php#6",
            "pie_csimex1.php#7","pie_csimex1.php#8","pie_csimex1.php#9" );

            // Strings to put as "alts" (and "title" value)
            $alts=array("val=%d","val=%d","val=%d","val=%d","val=%d","val=%d","val=%d","val=%d","val=%d");

            // Create a new scatter plot
            $sp1 = new ScatterPlot($datay,$datax);

            // Use diamonds as markerss
            $sp1->mark->SetType(MARK_DIAMOND);
            $sp1->mark->SetWidth(10);

            // Set the scatter plot image map targets
            $sp1->SetCSIMTargets($targ,$alts);

            // Add the plot
            $graph->Add($sp1);

            // Send back the HTML page which will call this script again
            // to retrieve the image.
            $graph->StrokeCSIM();

上面的代码通过显示分散的图形工作正常...但我想在同一页面嵌入一些PHP代码,如果我这样做它不起作用....根据一些专家的建议我更换 $graph->StrokeCSIM();

与                 `$ fileName =“。/ lang/12345.png”;                 $ graph-> img->流($文件名);

            echo('<img src="./lang/12345.png" />');`

它使用12345.png创建一个文件并且不显示图形...我该如何解决这个问题?

使用代码更新了问题....

            $_GET['Variance']=$Variance;
            $_GET['Emp_RecFactor']=$Emp_RecFactor;


            // Some data for the points
            $datax =$Emp_RecFactor;
            $datay =$Variance;



            // A new scatter graph
            $graph = new Graph(600,600);
            $graph->SetScale('intlin',-10,10,0,100);
            $graph->yscale->ticks->Set(1);
            $graph->xscale->ticks->Set(5);

            //$graph->img->SetMargin(40,40,40,40);        

             $graph->xaxis->title->Set("Reco-Factor");
            $graph->yaxis->title->Set("Variance");
            $graph->title->Set("Equity Graph Of All Employees");
            $graph->title->SetFont(FF_FONT1,FS_BOLD);

            // Client side image map targets
            $targ=array("pie_csimex1.php#1","pie_csimex1.php#2","pie_csimex1.php#3",
            "pie_csimex1.php#4","pie_csimex1.php#5","pie_csimex1.php#6",
            "pie_csimex1.php#7","pie_csimex1.php#8","pie_csimex1.php#9" );

            // Strings to put as "alts" (and "title" value)
            $alts=array("val=%d","val=%d","val=%d","val=%d","val=%d","val=%d","val=%d","val=%d","val=%d");

            // Create a new scatter plot
            $sp1 = new ScatterPlot($datay,$datax);

            // Use diamonds as markerss
            $sp1->mark->SetType(MARK_DIAMOND);
            $sp1->mark->SetWidth(10);

            // Set the scatter plot image map targets
            $sp1->SetCSIMTargets($targ,$alts);

            // Add the plot
            $graph->Add($sp1);

            // Send back the HTML page which will call this script again
            // to retrieve the image.



            $graph->Strokecsim();

test2.php包含...

            echo "<p>hello</p>";
            include "Talent_Graphcopy.php"; // containing the graph code
            echo "<p>goodbye</p>";

1 个答案:

答案 0 :(得分:0)

$ graph-&gt; StrokeCSIM()以图像映射的形式生成图形。包含此代码的PHP(我们称之为图形脚本)能够生成支持HTML和图形图像本身。

当调用没有参数的图表脚本(例如http://contoso.com/graph.php)时,会生成HTML。生成的HTML包含一个IMG标记,该标记使用魔术参数(例如<img src="graph.php?_jpg_csimd=1")指向脚本本身。使用magic参数调用脚本时,会生成图像。

您不能将生成HTML输出的PHP代码放入图形脚本中,因为它会阻止图像生成功能正常工作。如果要将自定义HTML与图形输出混合,可以将图形脚本包含在另一个PHP脚本中。

e.g。 Display.php的

echo "<p>hello</p>";
include "Talent_Graphcopy.php"; // containing the graph code
echo "<p>goodbye</p>";

Talent_Graphcopy.php

// fancy graph code...
$graph->StrokeCSIM("Talent_Graphcopy.php"); 

指定图形脚本的名称作为StrokeCSIM的参数。它告诉脚本将IMG SRC设置为指向图形脚本本身以生成图形。如果你没有指定它,IMG SRC将指向Display.php ...这是错误的,因为浏览器会询问Display.php图像,它显然无法提供。