php 向jpGraph添加水平线或带

wmtdaxz3  于 2023-04-04  发布在  PHP
关注(0)|答案(1)|浏览(145)

我试图添加一个简单的水平线(或带)到我的图表,由于某些原因,它不显示任何东西。
我使用了这些线:
$graph->AddLine(new PlotLine(HORIZONTAL,0,"black",2));

$graph->AddBand(new PlotBand(HORIZONTAL,BAND_RDIAG,0, "max", "red", 2));
如图所示https://jpgraph.net/download/manuals/classref/Graph.html
还有什么我应该做的吗?有没有一个特定的地方我应该把它放在哪里?我把它们放在$graph->Add($lineplot);后面
谢谢你的帮忙

kgsdhlau

kgsdhlau1#

首先,你需要包含(require)jpgraph_plotline.php文件,比如:

require_once ('jpgraph-4.2.5/src/jpgraph_plotline.php');

然后,在$graph->Stroke();行之前,添加绘制该行的代码,例如:

// Create a line to add as markers
$l1 = new PlotLine(HORIZONTAL, 5, 'green:1.5', 10);
 // Add lines to the plot
$graph->AddLine($l1);

因此,整个代码将像这样:

<?php 
require_once ('jpgraph-4.2.5/src/jpgraph.php');
require_once ('jpgraph-4.2.5/src/jpgraph_line.php');
require_once ('jpgraph-4.2.5/src/jpgraph_plotline.php');

$datay1 = array(20,15,23,15);
$datay2 = array(12,9,42,8);
$datay3 = array(5,17,32,24);

// Setup the graph
$graph = new Graph(300,250);
$graph->SetScale("textlin");
$graph->title->Set('StackOverflow.com');
$graph->SetBox(false);
$graph->SetMargin(40,20,36,63);

// Create the first line
$p1 = new LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#6495ED");
$p1->SetLegend('Line 1');

// Create the second line
$p2 = new LinePlot($datay2);
$graph->Add($p2);
$p2->SetColor("#B22222");
$p2->SetLegend('Line 2');

// Create the third line
$p3 = new LinePlot($datay3);
$graph->Add($p3);
$p3->SetColor("#FF1493");
$p3->SetLegend('Line 3');

// Create a line to add as markers
$l1 = new PlotLine(HORIZONTAL, 5, 'green:1.5', 10);
 // Add lines to the plot
$graph->AddLine($l1);

// Output the result
$graph->Stroke();
?>

这样,绘图线将被添加到折线图上(如下所示-y位置5处的绿色线,宽度:10)

如果需要,只需对PlotBand执行相同的操作。
好好享受...

相关问题