Home Backend Development PHP Tutorial 用Flash图形化数据(一)_php基础

用Flash图形化数据(一)_php基础

May 17, 2016 am 09:47 AM

by Bryan Mattern  一木 译

SWF和Flash简介
    SWF是Macromedia Flash用来在Internet上向用户传送图片、动画和声音的文件格式。Flash是你能够向用户提供一个丰富的和动态的界面。大约90%的Web用户不用安装浏览器插件就可以浏览SWF内容,超过2亿人下载了Flash播放器。Macromedia在1998年4月公开了SWF规范。在PHP4中加入SWF的支持。
    PHP内建的动态生成图片的能力是一个吸引我的特征。它可以生成看起来更专业更让人舒服的报表和界面。一开始,我用充斥在网上的各种GD代码来创建图片来显示我的不同项目的数据。但我很快就被生成的图片的不确定搞烦了,决定试试看能不能用矢量图形来解决问题。我想你也会同意,结果看起来好多了。如果一个图片能代表一千个词,想象一下一幅Flash动画代表什么?
    我将尽量使这个例子简单一些,只说说基础的东西。我的目的只是创建一个容纳GD生成的GIF和PNG图片的Drog in。你可以加入对它的扩展和增强,比如Flash赖以出名的各种可视效果。例如,你可以制作在载入页面时的图形淡入、飞舞,或者动态的显示几片雪花。你的想象力是对PHP的SWF函数的唯一限制。
    怎样取得需要图形化的数据最好留给读者去练习。因为这篇文章是关于动态创建Flash文件的,我将在例子中使用一个假想的表作为数据集来创建它的图形化视图。你需要检查你的数据,决定采用一种最适合的图表形式。在多数情况下,饼图是一个合适的选择,这也是我的例子要采用的图表形式。折线图、柱状图或者面积图都可以用相似的方式创建。
    在这个例子中,假定我们把一些包裹送到了几个城市,而我们要看看每个城市收到的包裹所占的比例。我们决定把数据存储在数据库“world”的表“city”中。让我们先建立这个表,并输入这个例子需要的数据。

#
# 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', '20000917122625');
INSERT INTO city VALUES( '2', 'London', '20000917122626');
INSERT INTO city VALUES( '3', 'London', '20000917122626');
INSERT INTO city VALUES( '4', 'London', '20000917122627');
INSERT INTO city VALUES( '5', 'Paris', '20000917122631');
INSERT INTO city VALUES( '6', 'Paris', '20000917122632');
INSERT INTO city VALUES( '7', 'New York', '20000917122644');
INSERT INTO city VALUES( '8', 'New York', '20000917122645');
INSERT INTO city VALUES( '9', 'New York', '20000917122646');
INSERT INTO city VALUES( '10', 'New York', '20000917122646');
INSERT INTO city VALUES( '11', 'New York', '20000917122647');
INSERT INTO city VALUES( '12', 'Hong Kong', '20000917122654');


配置你的系统以使用SWF
    我用的环境是RedHat Linux6.2, Apache 1.3.12, PHP 4.0.2(编译为Apache模块)。如果你在Windows中使用PHP,事情会有些不同。你需要下载或者编译一个Flash Dll,但是不需要修改代码。
    PHP通过Paul Haeberli的libswf模块来提供创建Shockwave Flash 文件的能力。你需要从http://reality.sgi.com/grafica/flash/下载libswf。然后,你需要使用选项--with-swf[=DIR]来配置PHP,这里DIR是include和lib目录所在的目录。include目录下必须有swf.h文件,而lib目录下必须有libswf.a文件。当解压缩下载的libswf发布版本的时候,这两个文件会被解压缩到同一个目录。你需要把这两个文件移到正确的位置。完成后,目录结构应该像下面的样子:

    /usr/local/swf/
        /include/
            swf.h
        /lib/
            libswf.a
        /fonts
    ...

    为了使SWF函数能正常工作,你需要复制/usr/local/swf/fonts/目录,以便web服务器能访问该目录(对apache和mod_php来说,最好的办法就是使用绝对路径,并把以上目录复制到apache的文档根目录下。)另外,在libswf的发布版本中有一个很小的c程序,能够把类型1的字体转换成Flash能用的字体。
    因为我们要动态地创建和写SWF文件,所以web服务器需要在存储文件的目录有写权限。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

What are Enumerations (Enums) in PHP 8.1? What are Enumerations (Enums) in PHP 8.1? Apr 03, 2025 am 12:05 AM

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles