Openflashchart 2.0 Simple Case PHP version _php instance

Source: Internet
Author: User
Tags json strlen
1.openflashchart is a more practical icon rendering plug-in, but also open source, url http://teethgrinder.co.uk/open-flash-chart/

2.FlashChart class
Copy Code code 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 ' <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 class

Take a simple icon configuration from the already written txt text to load the class used: for example
Copy Code code 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": "Registered user amount (person)",
"width": 1,
"Dot-style": {
"Type": "Solid-dot", "colour": "#a44a80", "Dot-size": 3,
"Tip": "#val # person <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)
}
}

This is the content of the class:
Copy code code 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 the code
Copy Code code as follows:


<!--//The mychat here is to show the place of flash, so can not be empty, change words to declare Flashchart class when the definition, detailed see Flashchart class-->
<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 ' => ' "string 1\", \ "string 2\", \ "string 3\", \ "string 4\", \ "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, there is also a function of processing data, the query to convert the data set to OFC data

Copy Code code as follows:



/**
* @brief OFC data processing
* @params database to query the data set about the x,y axis
* @note Backstage
*/
/*
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.