php报表的使用:

1、到官网(http://jpgraph.net/)下载,建议下载jpgraph-3.0.7.tar.gz版本

2、解压后有两个文件夹

docportal:使用手册

src:报表核心文件

3、配置核心文件(对于src文件夹内容的操作)

1)创建一个jpgraph文件夹

2)将和Examples同级目录下的其它内容放在jpgraph文件夹下

3)将jpgraph放在Examples里

4)查找效果图。Examples里的每个php文件对应一个报表,可以在jpgraph11-3.0.7\docportal\chunkhtml\images查看报表的效果图,效果图的文件名和对应php文件的文件名相同

(如果你打开Examples文件夹里的某一个文件,你会发现有这样一句代码:require_once ('jpgraph/jpgraph.php')。但你却在该文件夹里没有找到jpgraph文件夹。其实jpgraph文件夹里的内容都放在和Examples同一目录下。因此你只要在Examples里创建一个jpgraph文件夹,并把和Examples同级目录的其它内容放到该文件夹里即可。)

4、引用方式:

1)直接访问php文件,如报表的效果图文件名为example27.1.png,则直接访问example27.1.php即可

2)作为图片引用,如<img alt="报表" src="example27.1.php" />

5、中文乱码处理

当你的文件为utf8时,会出现中文乱码,这时可使用iconv()将中文字符串转成gb2312。

例如:

$graph->title->Set(iconv("utf-8", "gb2312//ignore", "处理情况统计"));
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);

具体详见:http://blog.csdn.net/ms_x0828/article/details/5555864

6、案例分析

1)柱形图1

代码:

 1 <?php // content="text/plain; charset=utf-8"
 2 require_once ('jpgraph/jpgraph.php');
 3 require_once ('jpgraph/jpgraph_bar.php');
 4 
 5 
 6 $datay1=array(13,8,19);
 7 $datay2=array(3,0,0);//多增加的数据
 8 
 9 // Create the graph.
10 $graph = new Graph(650,450);//画布大小
11 //$graph->SetScale('textlin');
12 $graph->SetScale('textlin',-10,25);//设置y轴范围为5-75
13 $graph->yaxis->scale->ticks->Set(5);//设置y轴刻度为10
14 //$graph->xaxis->scale->ticks->Set(5);
15 $graph->xaxis->title->Set("X轴");
16 $graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD,14); 
17 $graph->yaxis->title->Set("Y轴");
18 $graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD,14); 
19 
20 $graph->SetMarginColor('white');//设置边框背景颜色
21 $graph->SetMargin(40,40,10,10);//设置图在边框中的位置
22 
23 // Setup title
24 $graph->title->Set('Acc bar with gradient呵呵');//设置标题,默认的标题不支持中文
25 $graph->title->SetFont(FF_SIMSUN,FS_BOLD,14);   //设置字体类型和大小。第一个参数决定是否能显示中文。参数值可参考jpgraph_ttf.inc.php文件
26 
27 // Create the first bar
28 $bplot = new BarPlot($datay1);
29 $bplot->SetFillGradient('AntiqueWhite2','AntiqueWhite4:0.8',GRAD_VERT);//设置柱体颜色
30 //$bplot->SetFillgradient('orange','darkred',GRAD_VER); //设置柱体颜色
31 $bplot->SetColor('orange');//柱体边界的颜色
32 
33 // Create the second bar
34 $bplot2 = new BarPlot($datay2);
35 $bplot2->SetFillGradient('olivedrab1','olivedrab4',GRAD_VERT);//柱体中增加部分的颜色
36 $bplot2->SetColor('red');//柱体中增加部分的边框颜色
37 
38 
39 // And join them in an accumulated bar
40 $accbplot = new AccBarPlot(array($bplot,$bplot2));
41 $graph->Add($accbplot);
42 
43 $graph->Stroke();
44 ?>
accbarframeex01.php

相关文章:

  • 2022-01-09
  • 2021-04-16
  • 2021-11-27
  • 2021-11-19
  • 2021-08-17
  • 2021-05-21
  • 2021-10-23
猜你喜欢
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2021-12-30
  • 2022-01-24
  • 2021-07-30
  • 2022-12-23
相关资源
相似解决方案