关于统计图库jpgraph的一些方法使用笔记

关于jpgraph的一些方法使用笔记

 

以前用PHP作图时必须要掌握复杂抽象的画图函数,或者借助一些网上下载的花柱形图、饼形图的类来实现。没有一个统一的chart类来实现图表的快速开发。

  而现在PHP有了一个统计图表库:JpGraph。专门提供图表的类库。它使得作图变成了一件非常简单的事情,你只需从数据库中取出相关数据,定义标题,图表类型,然后的事情就交给JpGraph,只需掌握为数不多的JpGraph内置函数(可以参照JpGraph附带例子学习),就可以画出非常炫目的图表!

 

首先设置显示的数据数组(多数时候是从数据库取出数据将其存储在数组里面)。

 

$graph=new Graph(450,320);  //设置图像的大小
 $graph->SetScale("intlin");
 $graph->SetShadow();     //设置显示阴影
 $graph->SetMargin(40,40,30,50);  //设置图形的边距
 $graph->SetAlphaBlending();

//设置图形的背景图片,填充方式有:BGIMG_FILLPLOT, BGIMG_FILLFRAME, BGIMG_COPY

$graph->SetBackgroundImage("abc.jpg",BGIMG_FILLPLOT);

$graph->AdjBackgroundImage(0,0); //设置背景图片的对比度,must be between -1 <= x <= 1, (0,0)=original image 
 $graph->title->Set($Expdate." ".$labName);//
 $graph->title->SetColor("#3399ff");
 $graph->title->SetFont(FF_SIMSUN,FS_BOLD,12); //设置标题字体,使用中文字体支持中文的显示
 //$graph->subtitle->Set($stuid);
 //$graph->subtitle->SetFont(FF_SIMSUN,FS_BOLD);
 //$graph->subtitle->SetColor('darkred');
 //$graph->xaxis->title->Set("Time");
 //$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
 $graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);//设置X轴字体样式
 $graph->xaxis->SetLabelAngle(45);   //set angle of the X-sacle data
 $graph->xaxis->title->SetColor("blue");
 $graph->xaxis->SetColor('green','red');
 //$graph->yaxis->title->Set("实测值");
 $graph->yaxis->title->SetFont(FF_SIMSUN,FS_NORMAL,11);
 $graph->yaxis->title->SetColor("blue");
 $graph->yaxis->SetColor("red",'blue');
 $graph->xaxis->SetLabelFormatCallback('TimeCallback');

//$graph->ygrid->Show(false); //设置是否显示格子。默认为显示;

$graph->ygrid->SetColor('yellow@0.5'); //设置格子的颜色和粗细。值越小,格子越粗。 
 $graph->img->SetAntiAliasing();       //设置折线的平滑状态
 $graph->SetMarginColor("#ccffcc");    //设置画布的背景色为浅蓝色
 $graph->yaxis->scale->SetGrace(20);    //设置y轴更优美一些

 $graph->legend->SetShadow('gray@0.5');  //设置图例阴影颜色和透明度
 $graph->legend->SetFont(FF_SIMSUN,FS_BOLD); //设置图例字体
 $graph->legend->SetFillColor( $plotline->SetColor('red');
 //$plotline->mark->SetType(MARK_STAR);
 //$plotline->mark->SetColor("red");
 //$plotline->mark->SetWidth(2);
 $plotline2->SetLegend("SetValue");
 $plotline2->SetColor("green");

 $graph->Add($plotline);
 $graph->Add($plotline2);

//生成本地图片

//$graph->Stroke(“路径/文件名.png”);
 $graph->Stroke($graph_dir."/".$Stuid."-".$Lab_id."-".$Expdate.".jpg");//设置生成的统计图的存放位置和名称

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值