|
|
PHP Sample Implementation - Anychart Flash Chart
ComponentCheck the sample of using PHP and
MySQL together with AnyChart.
Creating Table with PHP and MySQL
Download all source files in zip archive
For example, you have a MySQL database with Table, containig
info on your site visitors Internet Providers.
Here is an example how this table can be created and populated
using PHP (CreateTable.php):
|
<?php
$user_name
= "";
$user_password ="";
$host ="";
$base_name ="";
$data_base =mysql_connect($host.$user_name,$user_password);
$quer ="USE".$base_name;
mysql_query($quer,$data_base);
$quer ="CREATE
TABLE log (website TEXT, visitors DECIMAL(5))"
mysql_query($quer,$data_base);
mysql_close($data_base);
?> |
Insert rows in table
When the table is ready you can populate it with data:
|
$quer
= "INSERT INTO log
VALUES('sympatico.ca','42');";
mysql_query($quer,$data_base);
|
Retreive data from table
Previous two steps were only a prerequsite for the implementation
of dynamic chart with PHP and Anychart Flash Chart Component.
Let's start it.
Data table is ready and it is populated with data. Now
we need file, which will exract
data from table and present it in XML form.
|
<?php
$user_name
= "";
$user_password ="";
$host ="";
$base_name ="";
$data_base =mysql_connect($host.$user_name,$user_password);
$quer ="USE".$base_name;
mysql_query($quer,$data_base);
$quer= "SELECT website
FROM log";
$res_1= mysql_query($quer,$data_base);
$quer= "SELECT visitors
FROM log";
$res_2= mysql_query($quer,$data_base);
echo "<data>";
echo "<block>";
for ($i=0;$i<mysql_num_rows($res_1);$i++)
{
$site
= mysql_result($res_1,$i);
$visitors
= mysql_result($res_2,$i);
echo "<set
value='$visitors'
name='$site'
url='http://".$site.$"'/>";
}
echo "</data>";
echo "</block>";
mysql_close($data_base);
?>
|
XML output
Now we need file which will store Chart Properties and
at the same time contain data. We left only type
selection in this sample to make it clear, actually there
are many more settings in AnyChart XML file:
|
<?php
header("Content-Type:
text/xml" );
?>
<root>
<type>
<chart type='2DPie'/>
</type>
<? include"GetData.php";?>
</root>
|
Embedding Flash in Html Page
At last, we are just forming a html, containing embedded
Flash object:
<html>
<head>
<title>AnyChart PHP Sample</title>
</head>
<body bgcolor="#ffffff">
<object
classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"
width="550"
height="400"
id="RELEASE"
align="middle">
<param name="allowScriptAccess" value="sameDomain"
/>
<param name="movie" value="anychart.swf?XMLFile=XML.php"
/>
<param name="quality" value="high"
/>
<param name="bgcolor" value="#ffffff"
/>
<embed src="anychart.swf?XMLFile=XML.php"
quality="high" bgcolor="#ffffff"
width="550" height="400" name="RELEASE"
align="middle" allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer"
/>
</object>
</body>
</html>
|
|