openflashchart 2.0 简单案例php版
2015-01-24信息快讯网
openflashchart是一种比较实用的图标呈现插件,而且是开源的
1.openflashchart是一种比较实用的图标呈现插件,而且是开源的,网址http://teethgrinder.co.uk/open-flash-chart/2.FlashChart类
FlashChart Class Code
class FlashChart
{
private $id;
private $height;
private $width;
private $path;
function __construct($path="",$width=300,$height=500,$id="myChart")
{
global $flash_chart;
$this->id=$id;
$this->height=$height;
$this->width=$width;
$this->path=$path;
if(!$flash_chart)
{
echo '<script type="text/javascript" src="'.$path.'js/json/json2.js"></script>';
echo '<script type="text/javascript" src="'.$path.'js/swfobject.js"></script>';
echo '<script type="text/javascript" src="'.$path.'js/jquery-1.4.4.min.js"></script>';
$flash_chart=true;
}
}
function __destruct()
{
unset($this->id,$this->height,$this->width,$this->path);
}
function setID($id)
{
$this->id=$id;
}
function setChart($file,$info)
{
$tp=new TemplateData($file);
echo '<script type="text/javascript">';
echo "data_{$this->id}=".$tp->changeInfo($info).';';
echo "function ofc_get_dataOf{$this->id}(){return JSON.stringify(data_{$this->id});}";
echo "swfobject.embedSWF('".$this->path."/open-flash-chart.swf', '$this->id', '$this->width','$this->height','9.0.0','expressInstall.swf',{'get-data':'ofc_get_dataOf{$this->id}'} )";
echo '</script>';
}
}
3,TemplateData类
把一个简单的图标的配置从已经写好的txt文本里取出来加载所用的类 :例如
{
"title":
{
"text":"(title)",
"style":"{color:#FF0000;font-size:24px;}"
},
"y_legend":{
"text": "iWebShop",
"style": "{color: #736AFF;font-size:16px;}"
},
"elements":[
{
"type": "line",
"colour": "#736AFF",
"text": "注册用户量(人)",
"width": 1,
"dot-style": {
"type":"solid-dot", "colour":"#a44a80", "dot-size": 3,
"tip":"#val#人<br>#x_label#" },
"on-show": {"type": "shrink-in", "cascade":1, "delay":0.5},
"values" : [(numbers)]
}
],
"x_axis":{
"labels": {
"labels":[(dates)]
}
},
"y_axis":{
"steps": (steps),
"max": (max)
}
}
这是类的内容:
class TemplateData
{
public $substitution;
private $templateFile;
function __construct($filename)
{
$this->templateFile=@file_get_contents($filename) or die("not find templateFile");
}
function __destruct() {
unset ($this->templateFile,$this->substitution);
}
function setTemplateFile($tfile)
{
$this->templateFile=$tfile;
}
function getTemplateFile()
{
return $this->templateFile;
}
function replaceReal($matches)
{
extract($this->substitution, EXTR_OVERWRITE);
return isset($$matches[1])?$$matches[1]:$matches[1];
}
function changeInfo($subs)
{
$this->substitution=$subs;
return preg_replace_callback("(\((\w+)\))",array(&$this, 'replaceReal'),$this->getTemplateFile());
}
}
4,调用的代码
<!--//这里的myChat是显示flash的地方,所以不能为空,改动的话要在声明FlashChart类的时候定义,详细见FlashChart类-->
<div class='content_box'><div id="myChart"></div></div>
<?php
include("flashchart.php");
include("templatedata.php");
$fc=new FlashChart('chart/',"100%",320);
$infos=array(
'numbers'=>"30000,10000,5000,6000000,700",
'dates'=>"\"字符串1\",\"字符串2\",\"字符串3\",\"字符串4\",\"字符串5\"",
'steps'=>600000,
'max'=>6000000
);
$info=array("title"=>'用户注册统计','numbers'=>$infos['numbers'],'dates'=>$infos['dates'],'steps'=>$infos['steps'],'max'=>$infos['max']);
$fc->setChart("chart/templatechart/user-add.txt",$info);
5,还有一个处理数据的函数,把查询出来的数据集转换成ofc用的数据
/**
* @brief ofc数据处理
* @params 数据库查询出关于x,y轴的数据的数据集
* @note 后台
*/
/*
public function init_count($rs)
{
$numbers ='';
$dates = '';
$max = 0;
foreach($rs as $row)
{
$numbers .= $row['num'].',';//y轴数据
$dates .='"'.$row['month'].'",';//x轴数据
if($max<$row['num']) $max = $row['num'];
}
$steps=ceil($max/10);
$result= array(
'steps' => $steps,
'numbers' => strlen($numbers)>1 ? substr($numbers,0,-1):null,
'dates' => strlen($dates)>1 ? substr($dates,0,-1) : null,
'max' => $max+$steps
);
return $result;
}
深入array multisort排序原理的详解
使用Smarty 获取当前日期时间和格式化日期时间的方法详解
解析smarty模板中类似for的功能实现
smarty基础之拼接字符串的详解
php class中public,private,protected的区别以及实例分析
基于xcache的配置与使用详解
ubuntu下编译安装xcache for php5.3 的具体操作步骤
编译php 5.2.14+fpm+memcached(具体操作详解)
解析php中memcache的应用
深入Apache与Nginx的优缺点比较详解
CentOS 6.2使用yum安装LAMP以及phpMyadmin详解
PHP中array_merge和array相加的区别分析
深入PHP中的HashTable结构详解
joomla jce editor 解决上传中文名文件失败问题
PHP CodeBase:将时间显示为"刚刚""n分钟/小时前"的方法详解
基于HBase Thrift接口的一些使用问题及相关注意事项的详解
基于PHP字符串的比较函数strcmp()与strcasecmp()的使用详解
php class中self,parent,this的区别以及实例介绍
str_replace只替换一次字符串的方法
php提示undefined index的几种解决方法
PHP中去掉字符串首尾空格的方法
php的array_multisort()使用方法介绍
php array的学习笔记
php array的学习笔记
php提示Call-time pass-by-reference has been deprecated in的解决方法[已测]
apache mysql php 源码编译使用方法
PHP filter_var() 函数 Filter 函数
php 的加密函数 md5,crypt,base64_encode 等使用介绍
smarty巧妙处理iframe中内容页的代码
Php Ctemplate引擎开发相关内容
mysql总结之explain
php中echo()和print()、require()和include()等易混淆函数的区别
php addslashes及其他清除空格的方法是不安全的
PHP中创建空文件的代码[file_put_contents vs touch]
php中可能用来加密字符串的函数[base64_encode、urlencode、sha1]
114啦源码(114la)不能生成地方房产和地方报刊问题4级页面0字节的解决方法
PHP警告Cannot use a scalar value as an array的解决方法
shopex主机报错误请求解决方案(No such file or directory)
PHP性能优化工具篇Benchmark类调试执行时间