openflashchart 2.0 簡單案例php版
更新時(shí)間:2012年05月21日 03:01:26 作者:
openflashchart是一種比較實(shí)用的圖標(biāo)呈現(xiàn)插件,而且是開源的
1.openflashchart是一種比較實(shí)用的圖標(biāo)呈現(xiàn)插件,而且是開源的,網(wǎng)址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類
把一個(gè)簡單的圖標(biāo)的配置從已經(jīng)寫好的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": "注冊(cè)用戶量(人)",
"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)
}
}
這是類的內(nèi)容:
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,調(diào)用的代碼
<!--//這里的myChat是顯示flash的地方,所以不能為空,改動(dòng)的話要在聲明FlashChart類的時(shí)候定義,詳細(xì)見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"=>'用戶注冊(cè)統(tǒng)計(jì)','numbers'=>$infos['numbers'],'dates'=>$infos['dates'],'steps'=>$infos['steps'],'max'=>$infos['max']);
$fc->setChart("chart/templatechart/user-add.txt",$info);
5,還有一個(gè)處理數(shù)據(jù)的函數(shù),把查詢出來的數(shù)據(jù)集轉(zhuǎn)換成ofc用的數(shù)據(jù)
/**
* @brief ofc數(shù)據(jù)處理
* @params 數(shù)據(jù)庫查詢出關(guān)于x,y軸的數(shù)據(jù)的數(shù)據(jù)集
* @note 后臺(tái)
*/
/*
public function init_count($rs)
{
$numbers ='';
$dates = '';
$max = 0;
foreach($rs as $row)
{
$numbers .= $row['num'].',';//y軸數(shù)據(jù)
$dates .='"'.$row['month'].'",';//x軸數(shù)據(jù)
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;
}
2.FlashChart類
復(fù)制代碼 代碼如下:
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類
把一個(gè)簡單的圖標(biāo)的配置從已經(jīng)寫好的txt文本里取出來加載所用的類 :例如
復(fù)制代碼 代碼如下:
{
"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": "注冊(cè)用戶量(人)",
"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)
}
}
這是類的內(nèi)容:
復(fù)制代碼 代碼如下:
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,調(diào)用的代碼
復(fù)制代碼 代碼如下:
<!--//這里的myChat是顯示flash的地方,所以不能為空,改動(dòng)的話要在聲明FlashChart類的時(shí)候定義,詳細(xì)見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"=>'用戶注冊(cè)統(tǒng)計(jì)','numbers'=>$infos['numbers'],'dates'=>$infos['dates'],'steps'=>$infos['steps'],'max'=>$infos['max']);
$fc->setChart("chart/templatechart/user-add.txt",$info);
5,還有一個(gè)處理數(shù)據(jù)的函數(shù),把查詢出來的數(shù)據(jù)集轉(zhuǎn)換成ofc用的數(shù)據(jù)
復(fù)制代碼 代碼如下:
/**
* @brief ofc數(shù)據(jù)處理
* @params 數(shù)據(jù)庫查詢出關(guān)于x,y軸的數(shù)據(jù)的數(shù)據(jù)集
* @note 后臺(tái)
*/
/*
public function init_count($rs)
{
$numbers ='';
$dates = '';
$max = 0;
foreach($rs as $row)
{
$numbers .= $row['num'].',';//y軸數(shù)據(jù)
$dates .='"'.$row['month'].'",';//x軸數(shù)據(jù)
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;
}
相關(guān)文章
PHP實(shí)現(xiàn)一個(gè)輕量級(jí)容器的方法
這篇文章主要介紹了PHP實(shí)現(xiàn)一個(gè)輕量級(jí)容器的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-01-01PHP處理SQL腳本文件導(dǎo)入到MySQL的代碼實(shí)例
通常在制作安裝程式,數(shù)據(jù)備份程序的時(shí)候會(huì)要用到這樣的代碼,我看網(wǎng)上有是有不太多,而且有些也不是很好用,有時(shí)候這種代碼直接用現(xiàn)成的可以節(jié)省很多時(shí)間,那么我就從stackoverflow轉(zhuǎn)了一個(gè)過來,需要的朋友可以參考下2014-03-03PHP使用mysqli同時(shí)執(zhí)行多條sql查詢語句的實(shí)例
今天小編就為大家分享一篇關(guān)于PHP使用mysqli同時(shí)執(zhí)行多條sql查詢語句的實(shí)例,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-03-03php empty 函數(shù)判斷結(jié)果為空但實(shí)際值卻為非空的原因解析
這篇文章主要介紹了php empty 函數(shù)判斷結(jié)果為空但實(shí)際值卻為非空的原因解析,下面是腳本之家小編處理之后的調(diào)試記錄,分享到腳本之家平臺(tái),感興趣的朋友一起看看2018-05-05創(chuàng)建數(shù)據(jù)庫php代碼 用PHP寫出自己的BLOG系統(tǒng)
今天的任務(wù)是創(chuàng)建數(shù)據(jù)庫,因?yàn)閷?duì)數(shù)據(jù)庫懂的很少,所以在數(shù)據(jù)庫表關(guān)系上還很差啊。2010-04-04