Openflashchart 2.0 simple case php

Source: Internet
Author: User

1. openflashchart is a more practical icon rendering plug-in, and is open source, web site http://teethgrinder.co.uk/open-flash-chart/

2. FlashChart classCopy codeThe 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 '<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 ': 'oss _ get_dataOf {$ this-> id }'})";
Echo '</script> ';
}
}

3. TemplateData class

Extract the configuration of a simple icon from the txt text that has been written to load the class used: for exampleCopy codeThe 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 ",
"Color": "# 736AFF ",
"Text": "Number of registered users (persons )",
"Width": 1,
"Dot-style ":{
"Type": "solid-dot", "color": "# a44a80", "dot-size": 3,
"Tip": "# val # Persons <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 codeThe 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. Called codeCopy codeThe Code is as follows:

<! -- // Here, myChat is the place where flash is displayed, so it cannot be blank. If it is changed, it should be defined when the FlashChart class is declared. For details, see the FlashChart class -->
<Div class = 'content _ box'> <div id = "myChart"> </div>

<? Php
Include ("flashchart. php ");
Include ("templatedata. php ");
$ Fc = new FlashChart ('chart/', "100%", 320 );
$ Infos = array (
'Numbers '=> "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 data processing function that converts the queried dataset into ofc data.

Copy codeThe Code is as follows:

/**
* @ Brief ofc Data Processing
* @ Params database query a dataset with data off x and Y axes
* @ 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;
}

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.