2012-06-15 54 views
0

我一直在試圖在使用jpgraph php代碼的一個屏幕上顯示兩個圖形。根據jpgraph,這可以通過以下兩種方法之一完成,參見here。雖然我可以使用$ graph-> Stroke()單獨出現四個圖中的任何一個。我不能爲我的生活制定出如何使用jpgraph示例中規定的任何一種方法將它們顯示在一起。附加文檔中的mgraph代碼對我來說看起來是正確的,但是不會出現任何內容。任何幫助,將不勝感激。乾杯PHP jpgraph不會顯示多個圖形

<?php require("sess_start.php");?><?php if ($_GET[sessid] > 0) { //show page if user has a valid session ?><?php 
// AppServerType:PHP4 

require("./../adodb/adodb.inc.php"); 
require("./../Connections/m_water.php"); 


include ("./../jpgraph/src/jpgraph.php"); 
include ("./../jpgraph/src/jpgraph_line.php"); 

$ydata = array(2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32); 
$datax = array("1","2","3","4","5","6","7","8","9","10","11","12"); 
$max_inshore_effort = array("8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8",  "8", "8", "8", "8", "8"); 
$max_offshore_effort = array("12", "12", "12", "12", "12", "12", "12", "12", "12", "12", "12", "12", "12", "12", "12", "12"); 


//-------------------------------------------------------------------------------------------------------------------------------- 
//GRAPH 1 

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

//$graph->xaxis-> SetTickLabels($datax); 
//$graph->xaxis->SetFont(FF_FONT2); 
//$graph->yaxis->SetFont(FF_FONT2); 


// Create the linear plot 
//$lineplot=new LinePlot($ydata); 


    // Add the plot to the graph 
    //$graph->Add($lineplot); 
    //$lineplot->SetColor('#DC143C'); //set the colour of the line this case dark red 
//$lineplot->SetWeight(1.5); // set the thickness of the line 
//$lineplot->SetLegend('Total group effort'); // add a description to the legend 
//$lineplot->mark->SetType(MARK_FILLEDCIRCLE,'',1.0); // determine what type of marker is used 
//$lineplot->mark->SetType(MARK_SQUARE,'',2.0); // determine what type of marker is used 
//$lineplot->mark->SetSize(6); 
//$lineplot->mark->SetColor('#000000'); // determine the colour of the outer line surrounding the marker 
//$lineplot->mark->SetFillColor('#DC143C'); // set the fill for the marker 


//$graph->img->SetMargin(60,60,50,80); 
//$graph->xaxis->SetTitle('Round', 'center'); 
//$graph->yaxis->SetTitle('Total group effort', 'center'); 
//$graph->xaxis->SetTitleMargin(12); 
//$graph->yaxis->SetTitleMargin(32); 

// Setup a nice title with a striped bevel background 
//$graph->title->Set("State of Area 1 (Inshore)"); // alter the title heading 
//$graph->title->SetFont(FF_ARIAL,FS_BOLD,16); // alter the font of the title and size 
    //$graph->title->SetColor('#FFFFFF'); // alter the colour of the title 
    //$graph->SetTitleBackground('#4682B4',TITLEBKG_STYLE1,TITLEBKG_FRAME_BEVEL); // insert 3d bevel for title 
      //$graph->SetTitleBackgroundFillStyle(TITLEBKG_FILLSTYLE_HSTRIPED,'blue','darkgreen'); // insert alternating horizontal lines across title fill box; 


//$graph->tabtitle->SetColor('navy','lightyellow','navy'); 

//$graph->yaxis->SetColor('#000000'); //set the colour of the y axis 
//$graph->xaxis->SetColor('#000000'); // set the colour of the x axis 

    // Change the fonts of the axis and title 
    //$graph->title->SetFont(FF_FONT1,FS_BOLD); 
    //$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD); 
//$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); 
//$graph->xaxis->SetTickSide(SIDE_DOWN); 
//$graph->xaxis->SetLabelMargin(6); 
//$graph->yaxis->SetTickSide(SIDE_LEFT); 
//$graph->yaxis->SetLabelMargin(8); 

    //$lineplot->SetColor("#DC143C"); 

// Add a second axis displaying the maximum effort allowed for inshore area 
//$p1 = new LinePlot($max_inshore_effort); 
//$graph->Add($p1); 
//$p1->SetColor("#2E8B57"); 
//$p1->SetLegend('Max effort inshore to stay abundant'); 
//$p1->SetWeight(3); // set the thickness of the line 
//$p1->SetCenter(); 
//$p1->SetStyle('longdashed'); 

//$graph->SetShadow(); 

    // Adjust the legend position 
    //$graph->legend->SetLayout(LEGEND_HOR); 
//$graph->legend->Pos(0.15,0.94,"bottom","center"); //adjust the position of the legend on the graph 
    //$graph->legend->SetFillColor('#D3D3D3'); 

    //-------------------------------------------------------------------------------------------------------------------------------- 
//GRAPH 2 

    // Create the graph. These two calls are always required 
$graph2 = new Graph(550,400,"auto"); 
$graph2->SetScale("textlin"); 

$graph2->xaxis-> SetTickLabels($datax); 
$graph2->xaxis->SetFont(FF_FONT2); 
$graph2->yaxis->SetFont(FF_FONT2); 


// Create the linear plot 
$lineplot2=new LinePlot($ydata); 


    // Add the plot to the graph 
    $graph2->Add($lineplot2); 
    $lineplot2->SetColor('#DC143C'); //set the colour of the line this case dark red 
    $lineplot2->SetWeight(1.5); // set the thickness of the line 
    $lineplot2->SetLegend('Total group effort'); // add a description to the legend 
    //$lineplot->mark->SetType(MARK_FILLEDCIRCLE,'',1.0); // determine what type of marker is used 
    $lineplot2->mark->SetType(MARK_SQUARE,'',2.0); // determine what type of marker is used 
    $lineplot2->mark->SetSize(6); 
    $lineplot2->mark->SetColor('#000000'); // determine the colour of the outer line surrounding the marker 
    $lineplot2->mark->SetFillColor('#DC143C'); // set the fill for the marker 


$graph2->img->SetMargin(60,60,50,80); 
$graph2->xaxis->SetTitle('Round', 'center'); 
$graph2->yaxis->SetTitle('Total group effort', 'center'); 
$graph2->xaxis->SetTitleMargin(12); 
$graph2->yaxis->SetTitleMargin(32); 

// Setup a nice title with a striped bevel background 
    $graph2->title->Set("State of Area 1 (Offshore)"); // alter the title heading 
    $graph2->title->SetFont(FF_ARIAL,FS_BOLD,16); // alter the font of the title and size 
    $graph2->title->SetColor('#FFFFFF'); // alter the colour of the title 
    $graph2->SetTitleBackground('#4682B4',TITLEBKG_STYLE1,TITLEBKG_FRAME_BEVEL); // insert 3d bevel for title 
//$graph->SetTitleBackgroundFillStyle(TITLEBKG_FILLSTYLE_HSTRIPED,'blue','darkgreen');  //  insert alternating horizontal lines across title fill box; 


$graph2->tabtitle->SetColor('navy','lightyellow','navy'); 

    $graph2->yaxis->SetColor('#000000'); //set the colour of the y axis 
$graph2->xaxis->SetColor('#000000'); // set the colour of the x axis 

// Change the fonts of the axis and title 
$graph2->title->SetFont(FF_FONT1,FS_BOLD); 
$graph2->yaxis->title->SetFont(FF_FONT1,FS_BOLD); 
$graph2->xaxis->title->SetFont(FF_FONT1,FS_BOLD); 
$graph2->xaxis->SetTickSide(SIDE_DOWN); 
$graph2->xaxis->SetLabelMargin(6); 
$graph2->yaxis->SetTickSide(SIDE_LEFT); 
$graph2->yaxis->SetLabelMargin(8); 

$lineplot2->SetColor("#DC143C"); 

// Add a second axis displaying the maximum effort allowed for inshore area 
$p12 = new LinePlot($max_offshore_effort); 
$graph2->Add($p12); 
$p12->SetColor("#0000CD"); 
$p12->SetLegend('Max effort offshore to stay abundant'); 
$p12->SetWeight(3); // set the thickness of the line 
$p12->SetCenter(); 
$p12->SetStyle('longdashed'); 

$graph2->SetShadow(); 

// Adjust the legend position 
$graph2->legend->SetLayout(LEGEND_HOR); 
$graph2->legend->Pos(0.15,0.94,"bottom","center"); //adjust the position of the legend on the graph 
$graph2->legend->SetFillColor('#D3D3D3'); 
//$handle2 = $graph2->Stroke(_IMG_HANDLER); 

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

// Create a combined graph 
     //$mgraph = new MGraph(); 
    //$xpos1=3;$ypos1=3; 
     //$xpos2=3;$ypos2=200; 
     //$mgraph->Add($graph); 
    //$mgraph->Add($graph2,$xpos2,$ypos2); 
    //$mgraph->Stroke(); 

?> 
    <?php } //show page if user has a valid session ?> 

回答

1

在您的代碼段,你正在使用$graph->Stroke();但你的變量名是$graph2
我不知道這是您的問題的原因,但在這種情況下,$graph->Stroke();將不輸出任何內容。

0

據我瞭解graph->Stroke()將會給作爲圖像文件和graph->Stroke;graph2->Stroke;等多個實例將覆蓋以前的只顯示最終的圖像輸出。 我建議做,就是做一個文件類似 plotgraph.php:

<?php 

$xdata=explode(",",$_GET['xdata']); 
$ydata=explode(",",$_GET['ydata']); 
$title=$_GET['graphtitle']; 
// and any other variales that you need 
// Your graph routines 
// .. including $p->add($xdata,$ydata); etc statements 
$graph->Stroke(); 
?> 

在你的主文件中添加語句像

<img src="plotgraph.php?xdata=comma_separated_xdata&ydata=comma_separated_ydata&graphtitle=your_graph_title"> 

這樣的話,你可以插入儘可能多根據您的需要使用不同的參數。我希望有點讓人費解。 (請注意,我沒有添加所有的圖形格式等,只是舉例說明如果你想爲每個圖形單獨的字體等格式,你必須用URL導出並使用$ _GET獲取。其他常用設置可以在你的plotgraph.php文件中)