Graphical data with Flash

Source: Internet
Author: User

Introduction to SWF and Flash
SWF is a file format used by Macromedia Flash to transmit images, animations, and sounds to users over the Internet. Flash is a rich and dynamic interface that you can provide users. About 90% of Web users can browse SWF content without installing browser plug-ins. More than 0.2 billion download Flash players. Macromedia published the SWF specification in April 1998. Add SWF support to PHP4.
PHP's built-in ability to dynamically generate images is a feature that attracts me. It can generate reports and interfaces that look more professional and more comfortable. At the beginning, I used a variety of GD code on the Internet to create images to display the data of my different projects. However, I soon got bored with the uncertainty of the generated image and decided to try to solve the problem with vector graphics. I think you will agree, and the result looks much better. If an image represents one thousand words, imagine what a Flash animation represents?
I will try my best to make this example a little simpler and just talk about the basic things. My goal is to create a Drog in that can hold GIF and PNG images generated by GD. You can add extensions and enhancements to it, such as various visual effects that Flash depends on. For example, you can make images that fade in and fly when loading pages, or dynamically display several pieces of snow. Your imagination is the only restriction on the SWF function of PHP.
It is best to leave readers with exercises to learn how to obtain graphical data. Because this article is about creating a Flash file dynamically, I will use an imaginary table as a dataset in the example to create its graphical view. You need to check your data and decide to adopt the most suitable chart format. In most cases, a pie chart is an appropriate choice. This is also the form of a chart in my example. Line charts, bar charts, or area charts can all be created in a similar way.
In this example, assume that we have sent some packages to several cities, and we want to see the proportion of packages received by each city. We decided to store the data in the database "world" table "city. Let's create this table and enter the data required in this example.

#
# Table structure for table 'city'
#

Drop table if exists city;
Create table city (
City_id int (14) not null auto_increment,
City_name varchar (255) not null,
City_timestamp timestamp (14 ),
Primary key (city_id)
);

#
# Dumping data for table 'city'
#

Insert into city VALUES ('1', 'London ', '123 ');
Insert into city VALUES ('2', 'London ', '123 ');
Insert into city VALUES ('3', 'London ', '123 ');
Insert into city VALUES ('4', 'London ', '123 ');
Insert into city VALUES ('5', 'Paris ', '123 ');
Insert into city VALUES ('6', 'Paris ', '123 ');
Insert into city VALUES ('7', 'New York ', '123 ');
Insert into city VALUES ('8', 'New York ', '123 ');
Insert into city VALUES ('9', 'New York ', '123 ');
Insert into city VALUES ('10', 'New York ', '123 ');
Insert into city VALUES ('11', 'New York ', '123 ');
Insert into city VALUES ('12', 'Hong Kong', '123 ');


Configure your system to use SWF
My environment is RedHat Linux6.2, Apache 1.3.12, PHP 4.0.2 (compiled as Apache Module ). If you use PHP in Windows, things may be different. You need to download or compile a Flash Dll without modifying the code.
PHP uses the libswf module of Paul Haeberli to create Shockwave Flash files. You need to download libswffrom http://reality.sgi.com/grafica/flash. Then, you need to use the option -- with-swf [= DIR] to configure PHP. Here, DIR is the directory where the include and lib directories are located. The include directory must contain swf. H files, and the lib directory must contain the libswf. a file. When you decompress the downloaded libswf version, the two files will be decompressed to the same directory. You need to move the two files to the correct location. After completion, the directory structure should look like the following:

/Usr/local/swf/
/Include/
Swf. h
/Lib/
Libswf.
/Fonts
...

To make the SWF function work properly, you need to copy the/usr/local/swf/fonts/directory so that the web server can access this directory (for apache and mod_php, the best way is to use the absolute path and copy the above directory to the apache document root directory .) In addition, there is a very small c program in the libswf release version, which can convert the font of type 1 to the font available in Flash.
Because we need to dynamically create and write SWF files, the web server must have the write permission in the directory where the files are stored.

Let's bake cookies (pie chart)
After the Shockwave Flash support in PHP is successfully installed, you can use PHP to create the Shockwave file. The best way to learn is to directly jump to the program, so let's look at the program below. The first file includes sample code for how to use the class, and shows how to embed a Flash file into an HTML document.

<? Php

// Include class needed for flash graph
Include ("class. pie. flash. php ");

Mysql_connect ("localhost", "root ","");

$ Query = "select distinct city_name, COUNT (city_id)
FROM city

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.