📄 php-swf charts tutorial chart_data.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0069)http://www.maani.us/charts/index.php?menu=Tutorial&submenu=Chart_Data -->
<HTML><HEAD><TITLE>PHP/SWF Charts > Tutorial > Chart_Data</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META
content="chart charts php swf php/swf xml xml/swf tool shockwave flash web graph graphs dynamic data Line column 3D Pie Stacked bar area Candlestick Scatter Mixed Jarir Maani charting plot"
name=Keywords>
<META
content="A simple, yet powerful PHP tool to create attractive web charts from dynamic data."
name=description><LINK
href="PHP-SWF Charts Tutorial Chart_Data.files/style.css" type=text/css
rel=stylesheet><LINK href="favicon.ico" type=image/x-icon rel=icon><LINK
href="favicon.ico" type=image/x-icon rel="shortcut icon">
<SCRIPT src="PHP-SWF Charts Tutorial Chart_Data.files/urchin.js"
type=text/javascript>
</SCRIPT>
<SCRIPT type=text/javascript>
_uacct = "UA-160905-1";
urchinTracker();
</SCRIPT>
<META content="MSHTML 6.00.2800.1595" name=GENERATOR></HEAD>
<BODY bottomMargin=0 leftMargin=0 topMargin=0 rightMargin=0 Marginwidth="0"
Marginheight="0"><!-- table width must be greater than ever needed to avoid menu shrinking -->
<TABLE height=600 cellSpacing=0 cellPadding=10 width="100%" align=left border=0
frame=void>
<TBODY>
<TR>
<TD class=header vAlign=center colSpan=2 height=30><!-- header start ========================================================= --><!-- <a href="/charts/index.php">PHP/SWF Charts</a> --><A
href="http://www.maani.us/charts/index.php"><FONT color=#aabbcc>PHP/SWF
Charts</FONT></A> <FONT color=#ff4400><SMALL>4.5</SMALL></FONT>
<!--<img src="graphics/blank.gif" width=20 height=1><font color=222222>|</font><img src="graphics/blank.gif" width=20 height=1>
<a href="/slideshow/"><font color=666666>PHP/SWF Slideshow</font></a>--><IMG
height=1 src="PHP-SWF Charts Tutorial Chart_Data.files/blank.gif"
width=20><FONT color=#222222>|</FONT><IMG height=1
src="PHP-SWF Charts Tutorial Chart_Data.files/blank.gif" width=20> <A
href="http://www.maani.us/xml_charts/"><FONT color=#666666>XML/SWF
Charts</FONT></A> <IMG height=1
src="PHP-SWF Charts Tutorial Chart_Data.files/blank.gif" width=20><FONT
color=#222222>|</FONT><IMG height=1
src="PHP-SWF Charts Tutorial Chart_Data.files/blank.gif" width=20> <A
href="http://www.maani.us/xml_slideshow/"><FONT color=#666666>XML/SWF
Slideshow</FONT></A> <IMG height=1
src="PHP-SWF Charts Tutorial Chart_Data.files/blank.gif" width=20><FONT
color=#222222>|</FONT><IMG height=1
src="PHP-SWF Charts Tutorial Chart_Data.files/blank.gif" width=20> <A
href="http://www.maani.us/gauge/"><FONT color=#666666>XML/SWF
Gauge</FONT></A> <!-- header end --></TD></TR>
<TR>
<TD class=menu width=150><!-- menu start ========================================================= --><!-- SiteSearch Google -->
<FORM action=http://www.google.com/search method=get><INPUT type=hidden
value=UTF-8 name=ie> <INPUT type=hidden value=UTF-8 name=oe> <INPUT
class=form maxLength=255 size=10 name=q> <INPUT class=form type=submit value=Search name=btnG> <INPUT type=hidden
value=www.maani.us/charts/ name=domains> <INPUT type=hidden
value=www.maani.us/charts/ name=sitesearch> </FORM>
<HR color=#888888 noShade SIZE=1>
<B><A
href="http://www.maani.us/charts/index.php?menu=Introduction">Introduction</A></B><BR><B><A
href="http://www.maani.us/charts/index.php?menu=Gallery">Gallery</A></B><BR><B><A
href="http://www.maani.us/charts/index.php?menu=Requirements">Requirements</A></B><BR><B><A
href="http://www.maani.us/charts/index.php?menu=Download">Download</A></B><BR><B><A
href="http://www.maani.us/charts/index.php?menu=Installation">Installation</A></B><BR><B><FONT
color=#dddddd>Tutorial</FONT></B><BR><SMALL> </SMALL><BR><SMALL> <A
href="http://www.maani.us/charts/index.php?menu=Tutorial&submenu=Basics">Basics</A></SMALL><BR><SMALL><B> Chart
Data</B></SMALL><BR><SMALL> <A
href="http://www.maani.us/charts/index.php?menu=Tutorial&submenu=Chart_Attributes">Chart
Attributes</A></SMALL><BR><SMALL> <A
href="http://www.maani.us/charts/index.php?menu=Tutorial&submenu=Chart_Source">Chart
Source</A></SMALL><BR><SMALL> </SMALL><BR><B><A
href="http://www.maani.us/charts/index.php?menu=Reference">Reference</A></B><BR><B><A
href="http://www.maani.us/charts/index.php?menu=FAQ">FAQ</A></B><BR>
<HR color=#888888 noShade SIZE=1>
<B><A
href="http://www.maani.us/charts/index.php?menu=License">License</A></B><BR><B><A
href="http://www.maani.us/charts/index.php?menu=Contact_Us">Contact
Us</A></B><BR><IMG height=150
src="PHP-SWF Charts Tutorial Chart_Data.files/blank.gif"> <!-- menu end --></TD>
<TD class=body><!-- body start ========================================================= -->
<TABLE cellSpacing=0 cellPadding=5 width="100%" align=left border=0>
<TBODY>
<TR>
<TD width=40><IMG
src="PHP-SWF Charts Tutorial Chart_Data.files/blank.gif"
width=20></TD><!-- left margin -->
<TD vAlign=top>
<P></P>
<TABLE cellSpacing=0 cellPadding=2 width="100%" border=0>
<TBODY>
<TR class=prev_next>
<TD align=left> <A
href="http://www.maani.us/charts/index.php?menu=Tutorial&submenu=Basics"><B><
previous</B></A></TD>
<TD align=right><A
href="http://www.maani.us/charts/index.php?menu=Tutorial&submenu=Chart_Attributes"><B>next
></B></A> </TD></TR></TBODY></TABLE>
<P></P>
<P> </P>
<P><IMG height=0
src="PHP-SWF Charts Tutorial Chart_Data.files/blank.gif"></P><!-- top margin -->
<P><B><BIG>Chart Data</BIG></B></P>
<P> </P>
<P>To create a chart, start by organizing the data in a table like
this:</P>
<P></P>
<TABLE borderColor=#666666 cellSpacing=0 cellPadding=3 width=400
border=1>
<TBODY>
<TR>
<TH bgColor=#eeeeee> </TH>
<TH bgColor=#eeeeee>2001</TH>
<TH bgColor=#eeeeee>2002</TH>
<TH bgColor=#eeeeee>2003</TH>
<TH bgColor=#eeeeee>2004</TH></TR>
<TR>
<TH bgColor=#eeeeee>Region A</TH>
<TD align=right>5</TD>
<TD align=right>10</TD>
<TD align=right>30</TD>
<TD align=right>63</TD></TR>
<TR>
<TH bgColor=#eeeeee>Region B</TH>
<TD align=right>100</TD>
<TD align=right>20</TD>
<TD align=right>65</TD>
<TD align=right>55</TD></TR>
<TR>
<TH bgColor=#eeeeee>Region C</TH>
<TD align=right>56</TD>
<TD align=right>21</TD>
<TD align=right>5</TD>
<TD align=right>90</TD></TR></TBODY></TABLE>
<P></P>
<P> </P>
<P>Then, translate the table into a PHP multi-dimensional array like
this:</P><!-- PHP -------------------------------------->
<P></P>
<TABLE cellPadding=10 border=0>
<TBODY>
<TR>
<TD class=php><FONT size=3><PRE><?php
$chart [ 'chart_data' ] = array ( array ( "", "2001", "2002", "2003", "2004" ),
array ( "Region A", 5, 10, 30, 63 ),
array ( "Region B", 100, 20, 65, 55 ),
array ( "Region C", 56, 21, 5, 90 )
);
?>
</PRE></FONT></TD></TR></TBODY></TABLE>
<P></P><!-- PHP -------------------------------------->
<P><B>Notice that:</B>
<UL>
<LI>The array mimics the table exactly. It contains the same
number of rows and columns
<LI>Even though the top left cell is empty, it's included in the
array as an empty string for consistency
<LI>All the row and column titles are strings. All the table
values are numbers
<LI>None of the array values are mapped to keys </LI></UL>
<P></P>
<P> </P>
<P>At this point, you can add the array to the chart's source:</P><!-- PHP -------------------------------------->
<P></P>
<TABLE cellPadding=10 border=0>
<TBODY>
<TR>
<TD class=php><FONT size=3><PRE><?php
include "charts.php";
<FONT color=#888888>//the chart's data</FONT>
$chart [ 'chart_data' ] = array ( array ( "", "2001", "2002", "2003", "2004" ),
array ( "Region A", 5, 10, 30, 63 ),
array ( "Region B", 100, 20, 65, 55 ),
array ( "Region C", 56, 21, 5, 90 )
);
<FONT color=#888888>//send the new data to charts.swf</FONT>
SendChartData ( $chart );
?>
</PRE></FONT></TD></TR></TBODY></TABLE>
<P></P><!-- PHP -------------------------------------->
<OBJECT id=charts
codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0
height=250 width=400
classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><PARAM NAME="movie" VALUE="charts.swf?library_path=charts_library&stage_width=400&stage_height=250&php_source=php%2FTutorial.php%3Fchart%3Ddata1%26time%3D0.84142000+1184727792"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#666666">
<EMBED
src='charts.swf?library_path=charts_library&stage_width=400&stage_height=250&php_source=php%2FTutorial.php%3Fchart%3Ddata1%26time%3D0.84142000+1184727792'
quality=high bgcolor=#666666 WIDTH=400 HEIGHT=250 NAME='charts'
ALIGN='' swLiveConnect='true' TYPE='application/x-shockwave-flash'
PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED></OBJECT>
<P> </P>
<HR color=#888888 noShade SIZE=1>
<P><B>PHP Array</B></P>
<P>The PHP multi-dimensional array can be created without using the
array () function. It can be created by explicitly setting values in
it:</P><!-- PHP -------------------------------------->
<P></P>
<TABLE cellPadding=10 border=0>
<TBODY>
<TR>
<TD class=php><FONT size=3><PRE><?php
<FONT color=#888888>//create the PHP multi-dimensional array by explicitly setting values in it</FONT>
$chart [ 'chart_data' ][ 0 ][ 0 ] = "";
$chart [ 'chart_data' ][ 0 ][ 1 ] = "2001";
$chart [ 'chart_data' ][ 0 ][ 2 ] = "2002";
$chart [ 'chart_data' ][ 0 ][ 3 ] = "2003";
$chart [ 'chart_data' ][ 0 ][ 4 ] = "2004";
$chart [ 'chart_data' ][ 1 ][ 0 ] = "Region A";
$chart [ 'chart_data' ][ 1 ][ 1 ] = 5;
$chart [ 'chart_data' ][ 1 ][ 2 ] = 10;
$chart [ 'chart_data' ][ 1 ][ 3 ] = 30;
$chart [ 'chart_data' ][ 1 ][ 4 ] = 63;
$chart [ 'chart_data' ][ 2 ][ 0 ] = "Region B";
$chart [ 'chart_data' ][ 2 ][ 1 ] = 100;
$chart [ 'chart_data' ][ 2 ][ 2 ] = 20;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -