我正在尝试使用带有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');
}
答案 0 :(得分:0)
img
标记调用每个图表
醇>
当你使用img
标签来src jpgraph的url时,strok'ed图被视为一个图像。这样,您可以在每个页面上放置多个图形,并将每个图形的代码分开。
答案 1 :(得分: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 & 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>