首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在JpGraph循环中包含多个图形的for

在JpGraph循环中包含多个图形的for
EN

Stack Overflow用户
提问于 2013-05-01 01:20:10
回答 2查看 990关注 0票数 0

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

代码语言:javascript
复制
$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');

}
EN

回答 2

Stack Overflow用户

发布于 2013-08-29 07:39:38

  1. 创建一个包含所有图形的常规html文件。
  2. 手动使用img标记或使用php循环

调用每个图形

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

票数 0
EN

Stack Overflow用户

发布于 2014-12-11 09:45:53

这是旧的,但我偶然发现它寻找答案如何添加多个jpgraph csim图像到一个页面。

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

在jpgraph文档示例中不清楚的关键是,两个图像脚本中的每一个都必须使用不同的变量名,例如$graph变量的$graph1、$graph2,并相应地描边,然后在display.php脚本中适当地引用这些变量

代码语言:javascript
复制
    <?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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16305550

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档