⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 php-swf charts tutorial chart_data.htm

📁 flash图形分析代码,可用于常见的web 文件图片的统计分析
💻 HTM
📖 第 1 页 / 共 2 页
字号:
$chart [ 'chart_data' ][ 2 ][ 3 ] = 65;
$chart [ 'chart_data' ][ 2 ][ 4 ] = 55;
$chart [ 'chart_data' ][ 3 ][ 0 ] = "Region C";
$chart [ 'chart_data' ][ 3 ][ 1 ] = 56;
$chart [ 'chart_data' ][ 3 ][ 2 ] = 21;
$chart [ 'chart_data' ][ 3 ][ 3 ] = 5;
$chart [ 'chart_data' ][ 3 ][ 4 ] = 90;

?>
</PRE></FONT></TD></TR></TBODY></TABLE>
            <P></P><!-- PHP -------------------------------------->
            <P>&nbsp;</P>
            <P>Here's a script that creates the PHP multi-dimensional array in 
            mixed ways, and generates random chart values:</P><!-- PHP -------------------------------------->
            <P></P>
            <TABLE cellPadding=10 border=0>
              <TBODY>
              <TR>
                <TD class=php><FONT size=3><PRE>&lt;?php
 
<FONT color=#888888>//create the PHP multi-dimensional array in mixed ways</FONT>
$chart [ 'chart_data' ][ 0 ] = array ( "",         "2001", "2002", "2003", "2004" );
$chart [ 'chart_data' ][ 1 ][ 0 ] = "Region A";
$chart [ 'chart_data' ][ 2 ][ 0 ] = "Region B";
$chart [ 'chart_data' ][ 3 ][ 0 ] = "Region C";

for ( $row = 1; $row &lt;= 3; $row++ ) {
   for ( $col = 1; $col &lt;= 4; $col++ ) {
      $chart [ 'chart_data' ][ $row ][ $col ] = rand ( 0, 100 );
   }
}

?&gt;
</PRE></FONT></TD></TR></TBODY></TABLE>
            <P></P><!-- PHP -------------------------------------->
            <P>&nbsp;</P>
            <P>For more information about PHP arrays, please see the PHP manual 
            at <A href="http://www.php.net/"><U><B><FONT 
            color=#222222>http://www.php.net</FONT></B></U></A>.</P>
            <P>&nbsp;</P>
            <HR color=#888888 noShade SIZE=1>

            <P><B>Databases</B></P>
            <P>If you're accessing the chart data from a database, the number of 
            databases and techniques to access them is too big to cover in 
            detail here. For detailed information about PHP and databases, 
            please see the corresponding section in the PHP manual at <A 
            href="http://www.php.net/"><U><B><FONT 
            color=#222222>http://www.php.net</FONT></B></U></A>.</P>
            <P>Here's one example showing how to get the data from a MySQL 
            database. The example assumes the database called <B>Accounting</B> 
            is already created, and it has a table called <B>Growth</B> that 
            looks like this:</P>
            <P>Database: <B>Accounting</B><BR>Table: <B>Growth</B></P>
            <P></P>
            <TABLE borderColor=#666666 cellSpacing=0 cellPadding=3 width=400 
            border=1>
              <TBODY>
              <TR>
                <TH bgColor=#eeeeee>Region</TH>
                <TH bgColor=#eeeeee>Year</TH>
                <TH bgColor=#eeeeee>Revenue</TH></TR>
              <TR>
                <TD>Region A</TD>
                <TD align=right>2001</TD>
                <TD align=right>5</TD></TR>
              <TR>
                <TD>Region A</TD>
                <TD align=right>2002</TD>
                <TD align=right>10</TD></TR>
              <TR>
                <TD>Region A</TD>
                <TD align=right>2003</TD>
                <TD align=right>30</TD></TR>
              <TR>
                <TD>Region A</TD>
                <TD align=right>2004</TD>
                <TD align=right>63</TD></TR>
              <TR>
                <TD>Region B</TD>
                <TD align=right>2001</TD>
                <TD align=right>100</TD></TR>
              <TR>
                <TD>Region B</TD>
                <TD align=right>2002</TD>
                <TD align=right>20</TD></TR>
              <TR>
                <TD>Region B</TD>
                <TD align=right>2003</TD>
                <TD align=right>65</TD></TR>
              <TR>
                <TD>Region B</TD>
                <TD align=right>2004</TD>
                <TD align=right>55</TD></TR>
              <TR>
                <TD>Region C</TD>
                <TD align=right>2001</TD>
                <TD align=right>56</TD></TR>
              <TR>
                <TD>Region C</TD>
                <TD align=right>2002</TD>
                <TD align=right>21</TD></TR>
              <TR>
                <TD>Region C</TD>
                <TD align=right>2003</TD>
                <TD align=right>5</TD></TR>
              <TR>
                <TD>Region C</TD>
                <TD align=right>2004</TD>
                <TD align=right>90</TD></TR></TBODY></TABLE>
            <P></P>
            <P>&nbsp;</P>
            <P>The task is to read and organize the data like this table, and 
            create the corresponding PHP multi-dimensional array:</P>
            <P></P>
            <TABLE borderColor=#666666 cellSpacing=0 cellPadding=3 width=400 
            border=1>
              <TBODY>
              <TR>
                <TH bgColor=#eeeeee>&nbsp;</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>&nbsp;</P><!-- PHP -------------------------------------->
            <P></P>
            <TABLE cellPadding=10 border=0>
              <TBODY>
              <TR>
                <TD class=php><FONT size=3><PRE>&lt;?php

<FONT color=#888888>//start the PHP multi-dimensional array and create the region titles</FONT>
$chart [ 'chart_data' ][ 0 ][ 0 ] = "";
$chart [ 'chart_data' ][ 1 ][ 0 ] = "Region A";
$chart [ 'chart_data' ][ 2 ][ 0 ] = "Region B";
$chart [ 'chart_data' ][ 3 ][ 0 ] = "Region C";

<FONT color=#888888>//connect to the database</FONT>
mysql_connect ( "host", "user", "password" );
mysql_select_db ( "Accounting" );

<FONT color=#888888>//get the smallest year to determine which year to start the chart with</FONT>
$result = mysql_query ( "SELECT MIN(Year) AS MinYear FROM Growth" );
$MinYear = mysql_result ( $result, 0, "MinYear" );

<FONT color=#888888>//get all the data in the Growth table</FONT>
$result = mysql_query ("SELECT * FROM Growth");

<FONT color=#888888>//extract the data from the query result one row at a time</FONT>
for ( $i=0; $i &lt; mysql_num_rows($result); $i++ ) {

   <FONT color=#888888>//determine which row in the PHP array the current data belongs to</FONT>
   switch ( mysql_result ( $result, $i, "Region" ) ) {
      case "Region A":
      $row = 1;
      break;

      case "Region B":
      $row = 2;
      break;

      case "Region C":
      $row = 3;
      break;
   }

   <FONT color=#888888>//determine which column in the PHP array the current data belongs to</FONT>
   $col = mysql_result ( $result, $i, "Year") - $MinYear + 1;

   <FONT color=#888888>//populate the PHP array with the Year title</FONT>
   $chart [ 'chart_data' ][ 0 ][ $col ] = mysql_result ( $result, $i, "Year");

   <FONT color=#888888>//populate the PHP array with the revenue data</FONT>
   $chart [ 'chart_data' ][ $row ][ $col ] = mysql_result ( $result, $i, "Revenue");
}

?&gt;
</PRE></FONT></TD></TR></TBODY></TABLE>
            <P></P><!-- PHP -------------------------------------->
            <P>&nbsp;</P>
            <P></P>
            <TABLE cellSpacing=0 cellPadding=2 width="100%" border=0>
              <TBODY>
              <TR class=prev_next>
                <TD align=left>&nbsp;<A 
                  href="http://www.maani.us/charts/index.php?menu=Tutorial&amp;submenu=Basics"><B>&lt; 
                  previous</B></A></TD>
                <TD align=right><A 
                  href="http://www.maani.us/charts/index.php?menu=Tutorial&amp;submenu=Chart_Attributes"><B>next 
                  &gt;</B></A>&nbsp;</TD></TR></TBODY></TABLE>
            <P></P></TD><!--
 google ========================================================= 
<td><img src="graphics/blank.gif" width=40></td><td valign=top bgcolor=eeeeee>

</td>
 google ========================================================= 
--></TR></TBODY></TABLE><!-- body end --></TD></TR>
  <TR>
    <TD align=middle colSpan=2 height=10><!-- footer start ========================================================= -->
      <HR color=#000000 noShade SIZE=2>
      <SMALL>Copyright ? 2003-2007, maani.us</SMALL> 
  <!-- footer end --></TD></TR></TBODY></TABLE>
<P>&nbsp;</P></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -