简单型

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
<?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;  //返回文件名
}
}


控制器 :

PHP
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.

Download:

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…

codeigniter 操作 图标相关推荐

  1. php ci sql性能时间,Codeigniter操作数据库表的优化写法总结

    用codeigniter也有一段时间了,一直没有做什么总结.现在总结一些Codeigniter操作数据库表的优化写法,虽说不全,但是也确实可以帮助那些刚刚上手CI的同学. 链接数据库 复制代码 代码如 ...

  2. Linux系统(一)文件系统、压缩、打包操作总结

    序言 当前的形势,.Net已经开源,.Net Core 正在跨平台,可见微软巨人在努力,在改变,在进步,在走向春天.从前被微软供作上帝的.Net从业者,如果不打开心扉面向开源,改变自己,那么很可能在不 ...

  3. tomcat下多个app 不同的图标_iOS平台设计规范(五)图标与图片

    无论是UI.交互,还是产品经理,都应该熟读iOS平台设计规范.这对我们的产品设计,百利而无一弊.    图标与图片(Icons and Images)   一.图片大小和分辨率(Image Size ...

  4. android菜单键选择图标,Android Design

    开发者文档 Action Bar "操作栏"对于 Android 应用来说是最重要的设计元素.它通常在应用运行的所有时间都待在屏幕顶部. 操作栏的主要目的是: 突出重要的操作 (例 ...

  5. 删了手机里的一个html文件,手机操作篇:手机上怎么删除pdf其中一页

    原标题:手机操作篇:手机上怎么删除pdf其中一页 怎么删除pdf其中一页?这个问题难倒了很多的人,这里,小编提供了一个既简单又实用的方法.那就是教大家手机上怎么删除pdf其中一页. 1.有两个准备工作 ...

  6. MAC文件图标自动排列+取消自动排列

    一.设置文件图标自动排列 访达进入文件夹-->上方操作图标 -->选择排列方式按 -->选择 control+command+1键 按名称排列 control+command+2键 ...

  7. 误删桌面上的 计算机 图片,桌面图标删除不了怎么办 桌面图片不见找回【图文】...

    桌面图标便是我们所下载的软件app的操作图标,很多时候,当我们下载了一些功能性很高的软件时,会被附带一些病毒软件下载到电脑桌面上.这个时候,很有可能出现无法删除附带软件图标的现象.最大的可能性便是因为 ...

  8. element的el-table列标题添加自定义图标

    大家好,我是小佑@小佐https://blog.csdn.net/Smell_rookie,是一名页面仔工程师,我会不定时在CSDN更新我的博客,有兴趣的可以点个关注来逛逛我的主页. 需求:开发中我们 ...

  9. VC TreeCtrl 添加图标 背景色透明

    一般情况下,我们如果碰到需要在程序中使用图标的问题,首先要想到要用图像列表CimlageList类,该类是相同尺寸的图像或图标的集合,每个图像或图标用以"0"为基准的索引号来表征, ...

最新文章

  1. app.vue 跳转页面_独立站如何提高产品页面转化呢?
  2. myeclipse快捷键大全
  3. android viewgroup 事件,android中viewgroup的事件传递分析
  4. 【sprinb-boot】@ComponentScan 使用
  5. ANR 问题一般解决思路
  6. java泛型实例化_java基础-泛型举例详解
  7. chrome 插件 IE Tab Multi 一款最接近 IE 的 Chrome扩展
  8. 潘多拉固件设置ipv6_WAN口获取单一IPv6地址时,内网使用IPv6的方法(教育网可用)...
  9. 《宽带与接入网技术》第四章 以太网接入技术
  10. Python可视化--条形图
  11. SkyEye硬件模拟平台
  12. 求三个数的最小公倍数的解法之美
  13. 2021csp-j2 题解
  14. 深入理解散列函数和散列表
  15. VR全景开发学习链接Three.js
  16. 一枝独秀 BugkuCTF-杂项-MISC
  17. 年末阿里百度等大厂技术面试题汇总,原理+实战+视频+源码
  18. 农民工看完都学会了!龙湖集团java研发
  19. iOS 应用退到管理后台 左上角图片未更新(或不显示)
  20. vuex如何在没有moudles的情况下,新增一个moudle

热门文章

  1. 20 MM配置-BP业务伙伴-定义业务伙伴和供应商编码保持一致
  2. cassandra可视化工具_耗时1个月整理!160种Python标准库、第三方库和外部工具都有了...
  3. pytorch学习2:pytorch搭建Alexnet网络
  4. oracle tirger_又一次发现Oracle太美之awr相关脚本简介
  5. C++:内存分几个区
  6. 什么是微调(Fine Tune)?什么时候使用什么样的微调?【数据量和数据相似度决定】
  7. python 遍历数组根据规律拆分,python 实现以相同规律打乱多组数据
  8. phpcms搜索功能(案例一)- 代码剥离篇
  9. PHP在线无人值守源码交易网站源码,集成支付宝微信接口
  10. PHP仿金蝶云ERP进销存V8网络多仓版源码