Main Products Download Purchase Support

Tutorials - Anychart Flash Chart Component

Description | Chart gallery | Tutorials 

PHP Sample Implementation - Anychart Flash Chart Component

Check 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
// connection properties
$user_name = "";
$user_password ="";
$host ="";
$base_name ="";
// connect and select base:
$data_base =mysql_connect($host.$user_name,$user_password);
$quer ="USE".$base_name;
mysql_query($quer,$data_base);
// creating table:
$quer ="CREATE TABLE log (website TEXT, visitors DECIMAL(5))"
mysql_query($quer,$data_base);
// close connection:
mysql_close($data_base);
?>

Insert rows in table

When the table is ready you can populate it with data:

// insert into table some values
$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
// GetData.php

// connection properties
$user_name = "";
$user_password ="";
$host ="";
$base_name ="";
// connect and select base:
$data_base =mysql_connect($host.$user_name,$user_password);
$quer ="USE".$base_name;
mysql_query($quer,$data_base);
// get Data:
$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>";
// close connection:
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
// XML.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>

Copyright ©2007 AnyChart.Com All rights reserved.