openflashchart 2.0 简单案例php版
前端之家收集整理的这篇文章主要介绍了
openflashchart 2.0 简单案例php版,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1.openflashchart是一种比较实用的图标呈现插件,而且是开源的,网址http://teethgrinder.co.uk/open-flash-chart/ 2.FlashChart类
<div class="codetitle"><a style="CURSOR: pointer" data="7000" class="copybut" id="copybut7000" onclick="doCopy('code7000')"> 代码如下:
<div class="codebody" id="code7000">
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">';
echo '<script type="text/javascript" src="'.$path.'js/swfobject.js">';
echo '<script type="text/javascript" src="'.$path.'js/jquery-1.4.4.min.js">';
$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_getdataOf{$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 '';
}
}
3,TemplateData类 把一个简单的图标的配置从已经写好的txt文本里取出来加载所用的类 :例如
<div class="codetitle">
<a style="CURSOR: pointer" data="98714" class="copybut" id="copybut98714" onclick="doCopy('code98714')"> 代码如下: <div class="codebody" id="code98714">
{
"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#人
#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)
}
}
这是类的
内容:
<div class="codetitle">
<a style="CURSOR: pointer" data="76688" class="copybut" id="copybut76688" onclick="doCopy('code76688')"> 代码如下: <div class="codebody" id="code76688">
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());
} }