到上面随便找个例子,点击进去,将其源码拷贝出来,这里拷贝的是?target=new_bar3.php
代码如下:
<?php // content="text/plain; charset=utf-8"
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_bar.php');
$datay=array(62,105,85,50);
// Create the graph. These two calls are always required
$graph = new Graph(350,220,'auto');
$graph->SetScale("textlin");
//$theme_class="DefaultTheme";
//$graph->SetTheme(new $theme_class());
// set major and minor tick positions manually
$graph->yaxis->SetTickPositions(array(0,30,60,90,120,150), array(15,45,75,105,135));
$graph->SetBox(false);
//$graph->ygrid->SetColor('gray');
$graph->ygrid->SetFill(false);
$graph->xaxis->SetTickLabels(array('A','B','C','D'));
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
// Create the bar plots
$b1plot = new BarPlot($datay);
// ...and add it to the graPH
$graph->Add($b1plot);
$b1plot->SetColor("white");
$b1plot->SetFillGradient("#4B0082","white",GRAD_LEFT_REFLECTION);
$b1plot->SetWidth(45);
$graph->title->Set("Bar Gradient(Left reflection)");
// Display the graph
$graph->Stroke();
?>
在服务器根目录新增文件jpgraph.php,将拷贝的代码粘贴上去,保存后通过浏览器访问,看到如下图:
因为我的目的是要制作pdf文件,所以需要把生成的图片保存成文件,把代码封装修改一下,制作成一个脚本文件,如下:
#!/usr/bin/php -q
<?php // content="text/plain; charset=utf-8"
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_bar.php');
require_once ('fpdf/fpdf.php');
$datay=array(62,105,85,50);
// Create the graph. These two calls are always required
$graph = new Graph(350,220,'auto');
$graph->SetScale("textlin");
//$theme_class="DefaultTheme";
//$graph->SetTheme(new $theme_class());
// set major and minor tick positions manually
$graph->yaxis->SetTickPositions(array(0,30,60,90,120,150), array(15,45,75,105,135));
$graph->SetBox(false);
//$graph->ygrid->SetColor('gray');
$graph->ygrid->SetFill(false);
$graph->xaxis->SetTickLabels(array('A','B','C','D'));
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
// Create the bar plots
$b1plot = new BarPlot($datay);
// ...and add it to the graPH
$graph->Add($b1plot);
$b1plot->SetColor("white");
$b1plot->SetFillGradient("#4B0082","white",GRAD_LEFT_REFLECTION);
$b1plot->SetWidth(45);
$graph->title->Set("Bar Gradient(Left reflection)");
// Display the graph
//$graph->Stroke();
$graph->Stroke("/tmp/test1.png");
?>
给上述文件添加执行权限后,可在/tmp/下生成test1.png图片