- 浏览: 13638263 次
- 性别:
- 来自: 洛杉矶
文章分类
- 全部博客 (1994)
- Php / Pear / Mysql / Node.js (378)
- Javascript /Jquery / Bootstrap / Web (435)
- Phone / IOS / Objective-C / Swift (137)
- Ubuntu / Mac / Github / Aptana / Nginx / Shell / Linux (335)
- Perl / Koha / Ruby / Markdown (8)
- Java / Jsp (12)
- Python 2 / Wxpython (25)
- Codeigniter / CakePHP (32)
- Div / Css / XML / HTML5 (179)
- WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra (275)
- Apache / VPN / Software (31)
- AS3.0/2.0 / Flex / Flash (45)
- Smarty (6)
- SEO (24)
- Google / Facebook / Pinterest / SNS (80)
- Tools (22)
最新评论
-
1455975567:
xuezhongyu01 写道wocan23 写道我想问下那个 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
xuezhongyu01:
wocan23 写道我想问下那个111.1是怎么得来的我也看不 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
18335864773:
试试 pageoffice 在线打开 PDF 文件吧. pag ...
jquery在线预览PDF文件,打开PDF文件 -
青春依旧:
opacity: 0.5; 个人喜欢这种方式!关于其他css特 ...
css透明度的设置 (兼容所有浏览器) -
July01:
推荐用StratoIO打印控件,浏览器和系统的兼容性都很好,而 ...
搞定网页打印自动分页问题
简单型
Charting
Panaci: A Charting Library
Panaci is an application library for CodeIgniter.
If your application needs to output graphic charts at run-time, such as
bar, line
area, step or impulse charts, then Panaci makes this rather easy.It
utilises the Panachart
charting class released under the GPL by Eugen Fernea.
Features
Compact (23k) and efficient code.
Bandwidth friendly, the average image size for a 450*250 image is around
2K
Can output to a file or directly to an HTTP stream
Supports several plot types eg. bars, lines, dots, areas, step, impulse
Supports multiple series plots on the same image
Supports automatic scaling of plot area by axis labels size
An example plot
Basic usage
From your controller
$params = array('width' => 450, 'height' => 250, 'margin' => 15, 'backgroundColor' => '#eeeeee'); $this->load->library('chart', $params);
From your Controller function
function graph() { $data_2001 = array(43,163,56,21,0,22,0,5,73,152,123,294); $data_2002 = array(134,101,26,46,22,64,0,28,8,0,50,50); $Labels = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); $this->chart->setTitle("Annual Rainfall","#000000",2); $this->chart->setLegend(SOLID, "#444444", "#ffffff", 2); $this->chart->setPlotArea(SOLID,"#444444", '#dddddd'); $this->chart->setFormat(0,',','.'); $this->chart->addSeries($data_2001,'dot','2001 ', SOLID,'#00ff00', '#00ff00'); $this->chart->addSeries($data_2002,'area','2002 ', SOLID,'#ff0000', '#00ffff'); $this->chart->setXAxis('#000000', SOLID, 1, "2001"); $this->chart->setYAxis('#000000', SOLID, 2, "Rainfall in MM"); $this->chart->setLabels($Labels, '#000000', 1, HORIZONTAL); $this->chart->setGrid("#bbbbbb", DASHED, "#bbbbbb", DOTTED); $this->chart->plot('./images/file.png'); $this->load->view('graph'); }
Demo and Documentation
There is an online demo available at Panaci
Download
A download is available from here Panaci
========================================
pChart是一个免费的PHP图表生成库,可以生成多种图表如饼图或者柱状图等等,
需要GD库的支持
。下面我来简单讲讲如何在CI中方便地使用它。
首先我们要下载
pChart。访问http://pchart.sourceforge.net/download.php
就可以下载到最新版的pChart,目前最新的版本是1.27。解压下载到的文件
,我们要用到的只是其中的pChart文件夹,里面有pChart.class、pCache.class和pData.class这三个文件。我们把pChart文件夹复制到
application/libraries
/
下面。
然后要准备字体,因为我们做报表很可能要输出中文
,所以必须使用一种中文字体,至于选什么字体就看你的喜好了(如果是商业用途的话请注意字体的版权以免引起版权纠纷),把中文字体的ttf文件复制到
application/libraries/pChart
下面即可。
通过库的形式
来使用pChart,因此在
application/libraries/
下面创建一个文件,命名为 Chart.php,代码如下:
<?php class Chart { function Chart() { include(APPPATH."libraries/pChart/pData.class"); include(APPPATH."libraries/pChart/pChart.class"); } function draw_line_graph($params) { $DataSet = new pData; $DataSet->AddPoint($params['data'],"Serie1"); //需要显示的数据 $DataSet->AddPoint($params['date'],"Serie2"); //横坐标的数据 $DataSet->AddSerie("Serie1"); $DataSet->SetAbsciseLabelSerie("Serie2"); $DataSet->SetSerieName("订单总金额","Serie1"); $DataSet->SetYAxisName("RMB"); //纵坐标上显示的文字 $DataSet->SetXAxisName('横坐标:日期'); //横坐标上显示的文字 $DataSet->SetXAxisFormat("date"); //横坐标的数据类型 $Test = new pChart($params['height'],$params['width']); //图表文件的高度和宽度 $Test->setDateFormat($params['date_format']); //横坐标显示的日期格式 $Test->setColorPalette(0,255,0,0); $Test->setFontProperties(APPPATH."libraries/pChart/FZLTXIHK.ttf",12); //设置使用的字体及字号 $Test->setGraphArea(60,60,$params['x_area'],$params['y_area']); //图形区域的高度和宽度 $Test->drawGraphArea(252,252,252); //线的颜色 $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); $Test->drawGrid(4,TRUE,230,230,230,255); $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255); $Test->setFontProperties(APPPATH."libraries/pChart/FZLTXIHK.ttf",8); //设置数据值所用字体及字号 $Test->writeValues($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1"); //输出每个点的数据值 $Test->setFontProperties(APPPATH."libraries/pChart/FZLTXIHK.ttf",11); //设置使用的字体及字号 $Test->drawLegend(75,65,$DataSet->GetDataDescription(),255,255,255); $Test->setFontProperties(APPPATH."libraries/pChart/FZLTXIHK.ttf",12); //设置使用的字体及字号 $Test->drawTitle(60,22,$params['title'],50,50,50,585); $imagefile='public/temp/'.$params['filename'].'.png'; //设置生成文件的保存路径 $Test->Render($imagefile); //生成文件 return $imagefile; //返回文件名 } }
控制器 :
function test(){ $this->load->library('chart'); //载入pChart库 $params['data']=array(100,200,150,600,230,150,510); //要显示的数据 for($i=0;$i<7;$i++){ $params['date'][$i]=1250217066+$i*86400; //要显示的日期,注意这里是Unix时间戳,pChart会自动传换成你要的格式 } $params['title']='销售报表'; //图片标题 $params['date_format']='m月j日';//设置日期格式 $params['filename']='test_image'; //文件名 $params['height']=600; //高度 $params['width']=300; //宽度 $params['x_area']=560; //图形区域高度 $params['y_area']=280; //图形区域宽度 $data['chart_image']=$this->chart->draw_line_graph($params);//生成图片 $data['baseurl']=site_url(); $this->load->view('test_view.html',$data); }
视图:test_view.html
<html> <head><title></title></head> <body> <img src="<?php echo $baseurl.$chart_image;?>" /> </body> </html>
最终生成的图表是这样的:
关于pChart的更多用法,请参考它的在线文档:
http://pchart.sourceforge.net/documentation.php
=======================================================
<!-- // end:header.php //--> <!-- CONTENT -->
Codeigniter: Intergrating OpenFlashCharts
Yes I know, it has been some time since I last posted anything on the site. Things have just been crazy at work, trying to get up to speed on using Pentaho for a major project. In fact, I might start posting some Pentaho related topics in the future. There’s definitely a need for more help and guides on using Pentaho for beginners.
Anyway, one of the things on the project was to pull data from Pentaho and display it inside OpenFlashCharts on a CI platform. If you don’t know what OpenFlashCharts is, go visit the website. It’s a pretty awesome kit.
There’s been quite a bit of chatter on the net about integrating CI
with OpenFlashCharts, but ever since version 2 came out there have been
more questions about how to do it.
In the new version of OpenFlashCharts, it uses the JSON format to
describe what type of chart to render in the flash object. OFC comes
with a bunch of libraries (in various programming languages) which will
generate the JSON format for the flash object. For PHP, the kit comes
with the generic PHP version and a PHP5 version.
Somebody by the name of Thomas did managed to stitch OpenFlashCharts 2 with CI and he posted it up on the CI wiki. So kudos to Thomas (whoever you are) for making my life easier. If you like you can download his library and give it a spin.
For Thomas, he used the PHP5 libraries of OpenFlashCharts, which unfortunately is a bit incomplete. I wasn’t able to generate more advance graphs such as Hollow Areas, Dotted lines etc. The flash object gave me an ‘infinity’ error. After some investigation, I found that the OFC PHP5 libraries are not generating the same JSON as the generic PHP version. Taking a page out of his book, I modified his library to work with the generic PHP version instead.
One advantage of doing this is that suddenly, you can apply all the tutorial codes on the OFC website because they were written for the generic PHP library and not the PHP5 version.
So, download the zip file and extract the files to the relevant
folders of your CI install. The assets folder should go to wherever you
put your stuff like images and javascript files. Just make sure you
change the view to reflect the correct path. I put my assets in the root
of my webserver folder, and I access my CI through http://dev.ci/
.
When I run the http://dev.ci/charts
, I would get this
graph with 3 data lines.
So how does it all work?
The OFC library, php-ofc-library
and the OpenFlashChartLib.php
can now be accessed by calling the load library call.
$this->load->library('OpenFlashChartLib', NULL, 'OFCL');
If you look inside the view folder for chart_view.php
,
you can see where the OFC flash object is getting its JSON feed from, http://dev.ci/charts/get_data
.
Inside get_data()
function of the charts controller,
it’s basically the same code as the tutorial at http://teethgrinder.co.uk/open-flash-chart-2/data-lines-2.php
The difference here is that instead of calling the
$chart = new open_flash_chart();
I’m now doing
$chart = $this->OFCL->create('open_flash_chart');
to perform the same instantiation but through the OpenFlashChartLib (OFCL) library.
So, just change all the object instantiation call accordingly, and the graph should show up nice and neat.
Here’s Dilbert to close out…
- Panaci.zip (35.5 KB)
- 下载次数: 2
- ci-ofc2.zip (314.3 KB)
- 下载次数: 2
发表评论
-
CakePHP你必须知道的21条技巧
2012-10-19 06:25 1849原文链接:http://www.avatarfinancial ... -
cakephp 1.3 Views
2012-10-09 06:12 1408Section 1 Views 视图 一个vie ... -
cakephp 1.3 Models
2012-10-09 06:07 2473Section 1 What is a model? ... -
cakephp 1.3 Controller
2012-10-09 05:49 3299Controller 一个controller用于管理 ... -
cakephp 1.3 配置CakePHP
2012-10-09 05:31 4602Section 1 数据库配置 app/config/ ... -
CakePHP 2.x十分钟博客教程
2012-10-07 01:27 243671. CakePHP2十分钟博客教 ... -
Create an Admin panel with CodeIgniter
2010-05-23 02:15 4143Create an Admin panel with Code ... -
Codeigniter Grid 使用方法 (flexigrid)
2010-05-23 02:05 2764来源:http://codeigniter.com/forum ... -
CI集成 ckeditor 配置
2010-05-23 01:34 3722配置 ckeditor 1.上传 下载 ckedito ... -
codeigniter 辅助函数 - 敏感词过滤
2010-05-05 06:18 4543我们都知道有些敏感的词汇是不适合出现在互联网上的,特别是在有用 ... -
实现简单 codeigniter 缓存 (cache)
2010-04-30 23:47 5235代码 class Test extends Contr ... -
CKEditor Helper for CodeIgniter
2010-04-19 00:37 3943Using CKEditor as a plugin in y ... -
codeigniter 生成 excel
2010-04-19 00:33 3288Excel Plugin Th ... -
CakePHP 中文手册
2010-04-14 21:04 2310基本概念 Section1 简介 ... -
利用 Cache_Lite代替codeigniter中的cache功能
2010-01-29 06:15 5472codeigniter的功能纵然强大,也有不足之处。其cach ... -
CodeIgniter 操作PDF ( Generating PDF files using CodeIgniter )
2010-01-03 04:03 3570PDF files rock! Some of the p ... -
CodeIgniter 合作 Authorize.net
2009-12-30 00:25 1558function payment(){ // 略... ... -
CodeIgniter 合作paypal
2009-12-30 00:15 2317<?php class Paypal extend ... -
CodeIgniter 操作 CSV
2009-12-29 07:17 4582A Comma separated values (CSV) ... -
codeigniter 操作 Rss
2009-12-29 07:12 1927I wrote a codeigniter library t ...
相关推荐
NULL 博文链接:https://justcoding.iteye.com/blog/561475
CodeIgniter_2.1.2 中文操作手冊
在不到一个小时的时间里,您安装并配置了 CodeIgniter,创建了一个包含主页、将信息添加到数据库...可以添加在数据库插入操作结束后发送电子邮件通知的功能。 目前,您只是掌握了开始使用 CodeIgniter 所需的一些内容。
CodeIgniter最新版本,开源、免费、轻量级的web编程,基于MVC的编程架构能大大提高php编码生产力。
PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter...
CodeIgniter框架
codeigniter 代码实例分享,基于jquery1.4,codeigniter,eclipse 开发
NULL 博文链接:https://justcoding.iteye.com/blog/558776
敏捷php开发框架CodeIgniter 1.7.1中文手册
CodeIgniter_2.1.4.zip
codeigniter分页
CodeIgniter 架构 教程. CodeIgniter 架构的使用说明教程.
CodeIgniter最新版 CodeIgniter1.72版 帮助文档 帮助文件
研究了半天的codeigniter,基本把结构弄清楚了。
codeigniter中文文档codeigniter中文文档codeigniter中文文档codeigniter中文文档codeigniter中文文档
CodeIgniter_2.0.0.zip CodeIgniter_2.0.0.zip CodeIgniter_2.0.0.zip
codeigniter(CI)中文手册下载