0

我正在尝试通过使用 JpGraph 的 for 循环来创建年度和月度图表。我读过你只能实例化每个图一次,并编写了代码来适应这种情况,方法是在 for 循环开始之前实例化图。在 Stroke() 调用之后,代码只会生成一个图形,并且不会创建更多图形。有任何想法吗?

$graph = new Graph(850,330);
$graph1 = new Graph(850,330);
$graph2 = new Graph(850,330);
$graph->SetScale('datint');
$graph1->SetScale('datint');
$graph2->SetScale('datint');
$graph->SetMargin(70,130,30,100);
$graph1->SetMargin(70,130,30,100);
$graph2->SetMargin(70,130,30,100);
$graph->xaxis->SetLabelFormatString('Y M d',true);

$graph1->xaxis->SetLabelFormatString('Y M d',true);
$graph2->xaxis->SetLabelFormatString('Y M d',true);
$graph->xaxis->SetLabelAngle(90);
$graph1->xaxis->SetLabelAngle(90);
$graph2->xaxis->SetLabelAngle(90);
foreach($dates as $dkey=>$dvalue){

$graph->title->Set("Transfer rate for ".$siteName." in ".$tUnits."/second");
$graph->subtitle->Set("Dates: ".$dvalueL." to ".$dvalueH." for ".$siteName." AND monflag is ".$monFlag.".");

             $graph->yscale->ticks->Set(20, 10);
             if($maxT < 10) {
  $graph->yscale->ticks->Set(1,1);
}
else if(10 < $maxT && $maxT <= 1024) {
  $graph->yscale->ticks->Set(10, 2);
} else if(1024 < $maxT && $maxT <= 1048576) {
  $graph->yscale->ticks->Set(10, 5);
} else if(1048576 < $maxT && $maxT <= 1073741824) {
  $graph->yscale->ticks->Set(20, 10);
}

             $graph1->yscale->ticks->Set(20, 10);
if($maxC < 10) {
  $graph1->yscale->ticks->Set(1,1);
} else if(10 < $maxC && $maxC <= 1024) {
  $graph1->yscale->ticks->Set(10, 2);
} else if(1024 < $maxC && $maxC <= 1048576) {
  $graph1->yscale->ticks->Set(10, 5);
} else if(1048576 < $maxC && $maxC <= 1073741824) {
  $graph1->yscale->ticks->Set(20, 10);
}


$graph->SetMarginColor("#F0F0F0");
$graph->SetColor("#FFFFFF");
$graph1->title->Set("Compression ratio for ".$siteName);
$graph1->subtitle->Set("Dates: ".$dvalueL." to ".$dvalueH." for ".$siteName." AND monflag is ".$monFlag.".");
$graph1->SetMarginColor("#F0F0F0");
$graph1->SetColor("#FFFFFF");
$graph2->yscale->ticks->Set(20, 10);
if($maxL < 10) {
  $graph2->yscale->ticks->Set(1,1);
} else if(10 < $maxL && $maxL <= 1000) {
  $graph2->yscale->ticks->Set(10, 2);
} else if(1000 < $maxL && $maxL <= 10000) {
  $graph2->yscale->ticks->Set(10, 5);
} else if(10000 < $maxL && $maxL <= 1000000) {
  $graph2->yscale->ticks->Set(20, 10);
}

$graph2->title->Set("Lag time for ".$siteName);
$graph2->subtitle->Set("Dates: ".$dvalueL." to ".$dvalueH." for ".$siteName." AND monflag is ".$monFlag.".");


$graph2->SetMarginColor("#F0F0F0");
$graph2->SetColor("#FFFFFF");
$lineplot=new LinePlot($transferDataCad,$transerDate);
$lineplotT=new LinePlot($transferDataTech,$transferDate);
$lineplotT2=new LinePlot($transferDataLocal,$transferDate);
$lineplot->SetColor('red');
$lineplotT->SetColor('green');
$lineplotT2->SetColor('black');
$lineplot->SetLegend('Volume: CAD');
$lineplotT->SetLegend('Volume: TECH');
$lineplotT2->SetLegend('Volume: LOCAL');




$graph->img->SetImgFormat("jpeg");
$lineplot->SetWeight(2);
$lineplotT->SetWeight(2);
$lineplotT2->SetWeight(2);



$lineplot->mark->SetType(MARK_X);
$lineplotT->mark->SetType(MARK_X);
$lineplotT2->mark->SetType(MARK_X);
$graph->Add($lineplot);
$graph->Add($lineplotT);
$graph->Add($lineplotT2);
$graph->xaxis->SetTitleSide(SIDE_TOP); 
$graph->yaxis->SetColor('blue','blue'); 
$graph->xaxis->SetColor('purple','purple'); 
$graph->xaxis->title->Set("Date");
$graph->yaxis->SetTitleSide(SIDE_RIGHT); 
$graph->yaxis->title->Set($tUnits."/second");

$lineplot1=new LinePlot($compDataCad,$compDate);
$lineplot1C=new LinePlot($compDataTech,$compDate);
$lineplot1C2=new LinePlot($compDataLocal,$compDate);
$lineplot1->SetColor('blue');
$lineplot1C->SetColor('orange');
$lineplot1C2->SetColor('purple');

$lineplot1->SetWeight(2);
$lineplot1C->SetWeight(2);
$lineplot1C2->SetWeight(2);
$lineplot1->mark->SetType(MARK_X);
$lineplot1C->mark->SetType(MARK_X);
$lineplot1C2->mark->SetType(MARK_X);



$lineplot1->SetLegend('Volume: CAD');
$lineplot1C->SetLegend('Volume: TECH');
$lineplot1C2->SetLegend('Volume: LOCAL');
$graph->legend->Pos(0.01,0.1,"right" ,"center");
$graph1->legend->Pos(0.01,0.1,"right" ,"center");

$graph1->img->SetImgFormat("jpeg");
$graph1->Add($lineplot1);
$graph1->Add($lineplot1C);
$graph1->Add($lineplot1C2);
$graph1->xaxis->SetTitleSide(SIDE_TOP); 
$graph1->yaxis->SetColor('blue','blue'); 
$graph1->xaxis->SetColor('red','red');
$graph1->xaxis->title->Set("Date");
$graph1->yaxis->SetTitleSide(SIDE_RIGHT); 
$graph1->yaxis->title->Set("Ratio");

$lineplot2=new LinePlot($lagDataCad,$lagDate);
$lineplot2C=new LinePlot($lagDataTech,$lagDate);
$lineplot2C2=new LinePlot($lagDataLocal,$lagDate);
$lineplot2->SetColor('blue');
$lineplot2C->SetColor('orange');
$lineplot2C2->SetColor('purple');

$lineplot2->SetWeight(2);
$lineplot2C->SetWeight(2);
$lineplot2C2->SetWeight(2);

$lineplot2->mark->SetType(MARK_X);
$lineplot2C->mark->SetType(MARK_X);
$lineplot2C2->mark->SetType(MARK_X);
$lineplot2->SetLegend('Volume: CAD');
$lineplot2C->SetLegend('Volume: TECH');
$lineplot2C2->SetLegend('Volume: LOCAL');
$graph2->legend->Pos(0.01,0.1,"right" ,"center");


$graph2->img->SetImgFormat("jpeg");
$graph2->Add($lineplot2);
$graph2->Add($lineplot2C);
$graph2->Add($lineplot2C2);
$graph2->xaxis->SetTitleSide(SIDE_TOP); 
$graph2->yaxis->SetColor('blue','blue'); 
$graph2->xaxis->SetColor('green','green');
$graph2->xaxis->title->Set("Date");
$graph2->yaxis->SetTitleSide(SIDE_RIGHT); 
$graph2->yaxis->title->Set("Seconds");
// Display the graphs


if($monFlag == 0){
    $graph->Stroke('/var/apps/asc/web/images/'.$siteName.$dTemp1.'tgraph.jpg');
    $graph1->Stroke('/var/apps/asc/web/images/'.$siteName.$dTemp1.'cgraph.jpg');
    $graph2->Stroke('/var/apps/asc/web/images/'.$siteName.$dTemp1.'lgraph.jpg');

}

if($monFlag == 1){
    $graph->Stroke('/var/apps/asc/web/images/'.$siteName.$dTemp1.$dTemp2.'tgraph.jpg');
    $graph1->Stroke('/var/apps/asc/web/images'.$siteName.$dTemp1.$dTemp2.'cgraph.jpg');
    $graph2->Stroke('/var/apps/asc/web/images'.$siteName.$dTemp1.$dTemp2.'lgraph.jpg');

}
4

2 回答 2

0

这很旧,但我在寻找如何将多个 jpgraph csim 图像添加到单个页面的答案时遇到了它。

基于 jpgraph 示例,我的成功步骤是使用以下文件 (display.php),该文件使用在单独的图像脚本 ($_graphfilename1, $_graphfilename2) 中创建的 CSIM 来显示多个图形。要显示 2 个图形,您需要三个单独的脚本,即 2 个图像脚本和用于组合显示的脚本。

jpgraph 文档示例中未明确的关键是 2 个图像脚本中的每一个都必须使用不同的变量名称,例如 $graph1 , $graph2 用于 $graph 变量,相应地对它们进行描边,然后在 display.php 中适当地引用它们脚本

    <?php

// The names of the graph scripts
$_graphfilename1 = 'projectcsim.php';
$_graphfilename2 = 'resultcsim.php';

// This is the filename of this HTML file
global $_wrapperfilename;
$_wrapperfilename = basename (__FILE__);

// Create a random mapname used to connect the image map with the image
$_mapname1 = '__mapname'.rand(0,1000000).'__';
$_mapname2 = '__mapname'.rand(0,1000000).'__';

// Get the graph scripts
require_once ($_graphfilename1);
require_once ($_graphfilename2);

// This line gets the image map and inserts it on the page
$imgmap1 = $graph1->GetHTMLImageMap($_mapname1);
$imgmap2 = $graph2->GetHTMLImageMap($_mapname2);
echo $imgmap1;
echo $imgmap2;

// Construct the <img> tags for Figure 1 &amp; 2 and rebuild the URL arguments
$imgtag1 = $graph1->GetCSIMImgHTML($_mapname1,$_graphfilename1);
$imgtag2 = $graph2->GetCSIMImgHTML($_mapname2,$_graphfilename2);
?>
<table border=0>
<tr><td valign="bottom">
<?php
echo $imgtag1;
?>
<br><b>Figure 1. </b>
</td></tr><tr>
<td valign="bottom">
<?php
echo $imgtag2;
?>
<br><b>Figure 2. </b>
</td>
</tr>
</table>
于 2014-12-11T01:45:53.323 回答
0
  1. 创建一个包含所有图表的常规 html 文件。
  2. img手动使用标签或使用 php 循环调用每个图形

当您使用imgtag 来 src jpgraph 的 url 时,描边的图形被视为图像。这样,您可以在每个页面上有多个图表,并将每个图表的代码分开。

于 2013-08-28T23:39:38.117 回答