Jpgraph的基本使用

一、Jpgraph安装配置

下载Jpgraph安装包


二、Jpgraph说明

   1、包含所需要的类库文件 require_once() ; 

   2、初始化数据  $data=array();  可以是通过URL参数传递的数据( GET 或 POST方式)

3、 创建Graph类实例  $graph=new Graph(); 

4、将数据添加到图形上   $graph->Add();

5、显示图片   $graph->Stroke();

 中文字体乱码问题

 Gpgraph默认显示汉字时是把汉字编码认为gb2312,转化为utf-8以后再显示,如果文件的编码方式是gb2312,只需把SetFont()方法的第一个参数设置为FF_SIMSUN即可

如果是utf-8编码的,需要先把汉字编码转化为gb2312,这样汉字才能正常显示

转换编码方式可以使用  iconv("UTF-8","gb2312",$x);

一些常用的方法:

$graph->title->Set(‘设置图表的标题’);

$graph->tabtitle->Set('设置图片头部文字');
$graph->xaxis->title->Set("设置X轴的标题");
$graph->yaxis->title->Set("设置Y轴的标题");

$graph->SetScale('textlin');   //设置刻度值类型

$graph->img->SetMargin(50,40,40,55);//边框间距(左右上下)

$graph->title->SetFont(FF_SIMSUN,FS_BOLD,12);//标题字体

$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD,10);

$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD,10);

$graph->xaxis->SetFont(FF_SIMSUN,FS_BOLD,12);//坐标柱上的字体

$graph->yaxis->SetFont(FF_SIMSUN,FS_BOLD,12);

$graph->title->SetColor('red');  ///标题颜色

$graph->xaxis->title->SetColor('red');

$graph->yaxis->title->SetColor('red');

$graph->xaxis->title->SetMargin(20);//距离坐标轴的距离
$graph->yaxis->title->SetMargin(20);//距离Y轴的距离

$linepot->SetColor('red');//折线的颜色(折线图)

$linepot->SetWeight(2);//折线的宽度

$linepot->value->SetFormat('%0.1f'); //值的格式化

$linepot->value->show(true);//显示值

$graph->SetBackGroundImage ( );设置背景

$graph->SetMarginColor('lightblue');//设置图形颜色

$graph->SetShadow();//

$graph->Set3DPerspecttive(); //设置3d效果图


$p1->SetTheme('water');//设置样式

$p1->SetCenter(0.5,0.55);//设置图形位置

$graph->legend->Pos(0.1,0.9);//设置注释文字的位置

$graph->legend->SetFont(FF_SIMSUN,FS_BOLD,12);//设置注释文字的字体

给出一个能事例

gradline.php

<?php // content="text/plain; charset=utf-8"

		require_once ('jpgraph/jpgraph.php');
		require_once ('jpgraph/jpgraph_line.php');
                $graph = new Graph($nLenth,$nWeith);
		$graph->SetMargin(80,60,60,60);	
		$graph->SetScale("intlin");
		$graph->SetBox();
		$graph->SetMarginColor('darkgreen@0.8');
		
		//设置标题
		$graph->title->Set(iconv("UTF-8","GB2312//IGNORE",$title));
		$graph->title->SetFont(FF_SIMSUN,FS_BOLD);
	
		// Setup a background gradient image
		$graph->SetBackgroundGradient('darkred','yellow',GRAD_HOR,BGRAD_PLOT);
		$graph->xaxis->SetTickLabels($datax);  
		$graph->yscale->SetAutoMin(0);

		$graph->xaxis->title->Set(iconv("UTF-8","GB2312//IGNORE",$xtitle)); 
		$graph->yaxis->title->Set(iconv("UTF-8","GB2312//IGNORE",$ytitle));

		///标题颜色
		$graph->title->SetColor('red');  
		$graph->xaxis->title->SetColor('red');
		$graph->yaxis->title->SetColor('red');

		// Create the line
		$p1 = new LinePlot($datay);
		$p1->SetFillGradient('white','darkgreen');
		$graph->Add($p1);

		// Output line
		$graph->Stroke();
?>

onlineGraph.php

<?php 

		$datax = json_decode($_GET['datax']);
		$datay = json_decode($_GET['datay']);
		$nLenth = 1300;
		$nWeith = 400;
		$title = "在线玩家统计";
		$xtitle = "time";
		$ytitle = "count";
		include_once "gradline.php";






评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值