Home > Backend Development > PHP Tutorial > openflashchart 2.0 simple case php version_PHP tutorial

openflashchart 2.0 simple case php version_PHP tutorial

WBOY
Release: 2016-07-21 15:18:50
Original
865 people have browsed it

1.openflashchart is a relatively practical icon rendering plug-in, and it is open source. The website is http://teethgrinder.co.uk/open-flash-chart/

2. FlashChart class

Copy code The code is as follows:

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 '';
echo '';
$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 '';
}
}

3, TemplateData class

puts a simple icon The configuration is taken out from the txt text that has been written to load the classes used: for example
Copy the code The code is as follows:

{
"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": "Number of registered users (people) ",
"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)
}
}

This is the content of the class:
Copy the code The code is as follows:



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, calling code
Copy code The code is as follows:





include("flashchart. php");
include("templatedata.php");
$fc=new FlashChart('chart/',"100%",320);
$infos=array(
' numbers'=>"30000,10000,5000,6000000,700",
'dates'=>""String1","String2","String3","String4" ,"String 5"",
'steps'=>600000,
'max'=>6000000
);
$info=array("title"=>'User Registration statistics','numbers'=>$infos['numbers'],'dates'=>$infos['dates'],'steps'=>$infos['steps'],'max'= >$infos['max']);
$fc->setChart("chart/templatechart/user-add.txt",$info);

5, and A function that processes data and converts the queried data set into data for OFC

Copy code The code is as follows:



/**
* @brief ofc data processing
* @params database queries the data set about the x, y axis data
* @note background
*/
/*
public function init_count($rs)
{

$numbers ='';
$dates = '';
$max = 0;
foreach($rs as $row)
{

$numbers .= $row['num'].', ';//y-axis data
$dates .='"'.$row['month'].'",';//x-axis data
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;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325447.htmlTechArticle1.openflashchart is a more practical icon rendering plug-in, and it is open source, the website is http://teethgrinder .co.uk/open-flash-chart/ 2. The FlashChart class copy code is as follows: FlashC...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template