Open-flash-chart and proxy Design
Directory
1 Open-flash-chart. 1
2. The simplest test case... 1
3 proxy... 2
3.1 why design proxy... 2
3.1 open-flash-chart model diagram... 4
3.2 model diagram after proxy... 4
3.3 benefits after proxy... 4
4. Example 5
4.1 line chart... 5
4.2 area chart... 6
4.3 compare the front-end page of the line chart and the front-end page of the area chart... 8
5 insufficiency and update... 8
6 attachment code test method... 8
1. Open-flash-Chart
Open-flash-chart is a statistical tool that uses open-flash-chart.swf as the statistical display end and supports HTTP data sources.
Http://teethgrinder.co.uk/open-flash-chart/
The following content is for version 1.9.6.
All code files and content are in UTF-8 format
2. Simplest Test Cases
The use of open-flash-chart consists of two parts:
1) Front-end display page
2) backend data page
The following is an example of a simple line chart.
1) Front-end display Page code test1.php
<? PHP Include_once 'ofc-Library/open_flash_chart_object.php '; Open_flash_chart_object (500,250, 'HTTP: // '. $ _ server ['server _ name'].'/1.9.6/data-1.php ', false ); ?> |
2) Back-end data page code
<? PHP Include_once ('ofc-Library/open-flash-chart.php '); $ Xarr = array ('Jan ', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug ', 'sept', 'oct', 'nov', 'dec '); $ Yarr = array ('1', '5', '7', '8', '4', '6', '9', '10 ', '12', '11', '13', '33 '); $ Ymax = 40; $ G = New Graph (); $ G-> title ('simplest example', '{font-size: 26px ;}'); $ G-> set_x_labels ($ xarr ); $ G-> set_data ($ yarr ); $ G-> set_y_max ($ Ymax ); Echo $ G-> render (); ?> |
3) Effect
3 proxy 3.1 why design proxy
Because we use open-free-chart to do the work each time, we may need to do two things.
1) make a front-end display page
2) create a background data source
Therefore, we hope to have a proxy class to complete the following work:
We hope to have a complete class for proxy operations on the front-end display page.
Class_myline
The functions are as follows:
(1) set the title
(2) set the data in the following format:
$ Lm_array = Array
(
"Qiyi" => array (
"00:00" => 20.64
"00:05" => 21.64
"" => 22.64
"00:15" => 53.64
),
"CNC" => array (
"00:00" => 30.64
"00:05" => 31.64
"" => 32.64
"00:15" => 13.64
),
"Letv" => array (
"00:00" => 40.64
"00:05" => 41.64
"" => 42.64
"00:15" => 43.64
"" => 44.64
"00:21" => 25.64
)
);
(3) directly output the above figure
3.1 open-flash-chart model Diagram
3.2 model diagram after proxy
3.3 benefits after proxy
1) data sorting and display are all in show page.
The background page only acts as a graphic-like driver and is no longer associated with data.
2) The data sorting method is summarized as the same. It is not related to the display of the image. You can easily change the graphic drive page from a line chart to an area chart.
4. Actual Example 4.1 line chart
1) Front-end page
<? PHP Include_once 'ofc-Library/open_flash_chart_object.php '; Include_once 'class _ myline. php '; Session_start (); $ Lm_array = Array ( "Qiyi" => array ( "" => 20.64, "" => 21.64, "00: 10" => 22.64, "" => 53.64, "" => 44.64, "00:21" => 25.64 ), ); $ ML = new class_myline (); $ Ml-> set_title ("Comparison of carrier traffic "); $ Ml-> set_xtitle ("time "); $ Ml-> set_ytitle ("Bandwidth "); $ Ml-> set_data ($ lm_array ); Var_dump ($ ml ); $ Char_data = serialize ($ ml ); $ _ Session ['Char _ data'] = $ char_data; Open_flash_chart_object (500,250, 'HTTP: // '. $ _ server ['server _ name'].'/1.9.6/data-ll.php ', false ); ?> |
2) graphic driver page
See data-ll.php
3) Effect
4.2 Area Chart
1) Front-end page
<? PHP Include_once 'ofc-Library/open_flash_chart_object.php '; Include_once 'class _ myline. php '; Session_start (); $ Lm_array = Array ( "Qiyi" => array ( "" => 20.64, "" => 21.64, "00: 10" => 22.64, "" => 53.64, "" => 44.64, "00:21" => 25.64 ) ); $ ML = new class_myline (); $ Ml-> set_title ("carrier traffic summary "); $ Ml-> set_xtitle ("time "); $ Ml-> set_ytitle ("Bandwidth "); $ Ml-> set_data ($ lm_array ); Var_dump ($ ml ); $ Char_data = serialize ($ ml ); $ _ Session ['Char _ data'] = $ char_data; Open_flash_chart_object (500,250, 'HTTP: // '. $ _ server ['server _ name'].'/1.9.6/data-area.php ', false ); ?> |
2) graphic driver page
See data-area.php
3) Effect
4.3 compare the front-end page and Area Chart front-end page of a line chart
As you can see, the current front-end page Code tends to be consistent
5 insufficiency and update
When multiple graphs are displayed on a page, parameters need to be included.
In this way, the data source of each graph can be pressed to different sessions.
Next, modify the driver page and retrieve different sessions for the corresponding parameters to deserialize and draw the image.
$ Char_data = serialize ($ ml ); $ _ Session ['chart _ data'. $ I] = $ char_data; Open_flash_chart_object (800,400, 'HTTP: // '. $ _ server ['server _ name'].': 8360/www/grah/data-lm.php? Chart_data = chart_data '. $ I, false ); |
6 attachment code Test Method
Decompress the entire 1.9.6.zip file to htdocs and then access your
Http: // server/1.9.6/test1.php
Http: // server/1.9.6/testll. php
Http: // server/1.9.6/testarea. php