Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP jpgraph赢得';不能显示多个图形_Php_Jpgraph - Fatal编程技术网

PHP jpgraph赢得';不能显示多个图形

PHP jpgraph赢得';不能显示多个图形,php,jpgraph,Php,Jpgraph,我一直在尝试使用jpgraph php代码在一个屏幕上显示两个图形。根据jpgraph,这可以通过以下两种方法之一完成,请参阅。虽然我可以使用$graph->Stroke()使四个图中的任何一个单独显示;我无法用jpgraph示例中规定的任何一种方法解决如何将它们一起显示的问题。随附文档中的mgraph代码在我看来是正确的,但不会显示任何内容。任何帮助都将不胜感激。干杯 <?php require("sess_start.php");?><?php if ($_GET[

我一直在尝试使用jpgraph php代码在一个屏幕上显示两个图形。根据jpgraph,这可以通过以下两种方法之一完成,请参阅。虽然我可以使用$graph->Stroke()使四个图中的任何一个单独显示;我无法用jpgraph示例中规定的任何一种方法解决如何将它们一起显示的问题。随附文档中的mgraph代码在我看来是正确的,但不会显示任何内容。任何帮助都将不胜感激。干杯

    <?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 ?>

?>
//创建一个组合图
//$mgraph=新的mgraph();
//$xpos1=3$ypos1=3;
//$xpos2=3$ypos2=200;
//$mgraph->Add($graph);
//$mgraph->Add($graph2、$xpos2、$ypos2);
//$mgraph->Stroke();
?>

在代码片段中,您正在使用
$graph->Stroke()
但您的变量名是
$graph2

我不知道这是否是问题的原因,但在本例中,
$graph->Stroke()
将不输出任何内容。

据我所知
图形->笔划()
将以图像文件和多个
图形->笔划实例的形式输出
图形2->笔划etc将覆盖以前仅显示最终图像的代码。
我建议做的是,制作一个类似
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文件中找到)