BI系统之统计图表的绘制[后端实现]
2014-03-14 15:03
295 查看
因为在开发内部BI系统中需要画出统计图表,我选了Jpgraph开源绘图工具实现需求。
之前实现过需求,没想到这次又花了很多时间回忆,各种搜索,真的是好记性不如烂笔头,
不会总结的人没有未来啊。
常用的三种图表样式:
[code]include("jpgraph/jpgraph_pie.php");
[/code]
[code]include("jpgraph/jpgraph_pie.php");
[/code]
[code]require_once('jpgraph/jpgraph_bar.php');
[/code]
以上为常用的图表及对应的后端实现:给自己记忆和需要人的便捷;
之前实现过需求,没想到这次又花了很多时间回忆,各种搜索,真的是好记性不如烂笔头,
不会总结的人没有未来啊。
常用的三种图表样式:
|————3D饼图:
include("jpgraph/jpgraph.php");
[code]include("jpgraph/jpgraph_pie.php");
include("jpgraph/jpgraph_pie3d.php");
$data=array(218,100);
$datatitle=array('男','女');
$title="男女占比";
$width=490;
$height=350;
$graph=newPieGraph($width,$height,'auto');
$graph->SetShadow();
$graph->title->Set($title);
$graph->title->SetFont(FF_SIMSUN,FS_BOLD,12);
$p1=newPiePlot3D($data);//创建3D饼形图对象
$p1->ExplodeSlice(1);//分割线
$p1->SetCenter(0.45);
$graph->legend->SetFont(FF_SIMSUN,FS_BOLD,10);//设置旁注字体
$graph->legend->Pos(0.89,0.9,'center','bottom');//设置旁注位置
$graph->legend->SetFrameWeight(0);//图例文字外框边框border设置为0
$graph->legend->SetFillColor('#FFFFFF');//图例文字框内的填充颜色
$graph->legend->SetShadow('#C8C8C8',0);
$graph->legend->SetLayout(LEGEND_VERT);//旁注摆放形式[竖直]
$p1->SetLegends($datatitle);
$graph->Add($p1);
$graph->Stroke();
[/code]
|—————普通圆形图:
include("jpgraph/jpgraph.php");
[code]include("jpgraph/jpgraph_pie.php");
$data=array(218,100);
$datatitle=array('男','女');
$title="男女占比";
$width=490;
$height=350;
$graph=newPieGraph($width,$height,'auto');
$graph->SetShadow();
$graph->title->Set($title);
$graph->title->SetFont(FF_SIMSUN,FS_BOLD,12);
$graph->legend->SetFont(FF_SIMSUN,FS_BOLD,10);//设置旁注字体
$graph->legend->Pos(0.89,0.9,'center','bottom');//设置旁注位置
$graph->legend->SetFrameWeight(0);//图例文字外框边框border设置为0
$graph->legend->SetFillColor('#FFFFFF');//图例文字框内的填充颜色
$graph->legend->SetShadow('#C8C8C8',0);
$graph->legend->SetLayout(LEGEND_VERT);//旁注摆放形式[竖直]
//Createpieplot
$p1=newPiePlot($data);
$p1->SetCenter(0.5,0.55);
$p1->SetSize(0.3);
//Enableandsetpolicyforguide-lines.Makelabelslineupvertically
$p1->SetGuideLines(true,false);
$p1->SetGuideLinesAdjust(1.1);
$p1->SetLegends($datatitle);
//Setupthelabels
$p1->SetLabelType(PIE_VALUE_PER);
$p1->value->Show();
$p1->value->SetFont(FF_ARIAL,FS_NORMAL,9);
$p1->value->SetFormat('%2.1f%%');
$graph->legend->SetLayout(LEGEND_VERT);
$graph->Add($p1);
$graph->Stroke();
[/code]
|————柱状图:
require_once('jpgraph/jpgraph.php');
[code]require_once('jpgraph/jpgraph_bar.php');
$datay=array('23','12','4','67','9');
$datax=array('0-10','11-50','51-100','101-500','500+');
$title="综合排名";
$width=520;
$height=380;
//Setthebasicparametersofthegraph
$graph=newGraph($width,$height,'auto');
$graph->SetScale("textlin");
$top=50;
$bottom=80;
$left=80;
$right=25;
$graph->Set90AndMargin($left,$right,$top,$bottom);
$graph->xaxis->SetPos('min');
//Niceshadow
$graph->SetShadow();
//Setuptitle
$graph->title->Set($title);
$graph->title->SetFont(FF_SIMSUN,FS_BOLD,10);
//SetupX-axis
$graph->xaxis->SetTickLabels($datax);
//
$graph->xaxis->SetFont(FF_SIMSUN,FS_BOLD,12);
//Someextramarginlooksnicer
$graph->xaxis->SetLabelMargin(5);
//LabelalignforX-axis
$graph->xaxis->SetLabelAlign('right','center');
//Addsomegracetoy-axissothebarsdoesn'tgo
//allthewaytotheendoftheplotarea
$graph->yaxis->scale->SetGrace(20);
//SetuptheY-axistobedisplayedinthebottomofthe
//graph.Wealsofinetunetheexactlayoutofthetitle,
//ticksandlabelstomakethemlooknice.
$graph->yaxis->SetPos('max');
//Firstmakethelabelslookright
$graph->yaxis->SetLabelAlign('center','top');
$graph->yaxis->SetLabelFormat('%d');
$graph->yaxis->SetLabelSide(SIDE_RIGHT);
//Thefixthetickmarks
$graph->yaxis->SetTickSide(SIDE_LEFT);
//Finallysetupthetitle
$graph->yaxis->SetTitleSide(SIDE_RIGHT);
$graph->yaxis->SetTitleMargin(35);
//Nowcreateabarpot
$bplot=newBarPlot($datay);
$bplot->SetFillColor("orange");
$bplot->SetShadow();
//Youcanchangethewidthofthebarsifyoulike
//$bplot->SetWidth(0.5);
//Wewanttodisplaythevalueofeachbaratthetop
$bplot->value->Show();
$bplot->value->SetFont(FF_ARIAL,FS_BOLD,12);
$bplot->value->SetAlign('left','center');
$bplot->value->SetColor("black","darkred");
$bplot->value->SetFormat('%.1fmkr');
//Addthebartothegraph
$graph->Add($bplot);
$graph->Stroke();
[/code]
以上为常用的图表及对应的后端实现:给自己记忆和需要人的便捷;
相关文章推荐
- mschart 实现统计图表绘制
- 用VML技术实现统计图形的绘制(考试系统中的试卷分析模块)
- iOS 使用 Core Plot 绘制统计图表入门[转]
- Android实现图表绘制和展示
- 完整版ajax+百度echarts实现统计图表demo并随着窗口大小改变而自适应
- asp.net下使用C#实现动态绘制图表
- iOS 使用 Core Plot 绘制统计图表入门
- [转载]Winform开发框架之统计图表的实现
- 实现数据的图表统计
- ASP.NET MVC 3实现访问统计系统
- asp 实现同一帐号,防止多人同时登录、获取在线列表、实现登录日志(可用户统计在线时长),适合用户访问量大的系统
- 用c#开发微信 (12) 微统计 - 阅读分享统计系统 2 业务逻辑实现
- 一道面试题--模拟实现简易的移动用户资费统计系统逻辑
- iOS 统计图表绘制(UITableView、UIBezierPath)
- Spring Boot + Spring Cloud 实现权限管理系统 后端篇(十九):服务消费(Ribbon、Feign)
- 中小型企业商业智能平台的开发和实现(数据仓库、BI系统、真实项目实战)
- shell脚本实现系统监视统计与数据备份
- java echarts.min.js实现统计图表
- C#实现绘制面形图表的方法详解
- Android实现图表绘制和展示