Main Products Download Purchase Support

Tutorials - Anychart Flash Chart Component

Description | Chart gallery | Tutorials 

ASP Sample Implementation - Anychart Flash Chart Component

Check the sample of using ASP and MSSQL Server together with AnyChart.

Creating Table with ASP and MSSQL Server

For example, you have a MSSQL Server database with Table, containig info on your site visitors Internet Providers.
Here is an example how this table can be created and populated using ASP (CreateTable.asp):

<%
Dim ConnectionString ' SQLServer Connection string
Dim cn ' SQLServer Connection object
Dim sqlQuery

' Form a connection string
' Choose ODBC or DSN connection and replace SERVER_NAME, UID, PWD and DB_NAME with real values

'strConnString = "driver={SQLServer};server=SERVER_NAME;uid=UID;pwd=PWD;database=DB_NAME" '## MS SQL Server 6.x/7.x/2000 (ODBC connection)
'strConnString = "Provider=SQLOLEDB;Data Source=SERVER_NAME;database=DB_NAME;uid=UID;pwd=PWD;" '## MS SQL Server 6.x/7.x/2000 (OLEDB connection)

' Create and open a connection
set cn = Server.CreateObject("ADODB.Connection")
cn.Open ConnectionString

' Form SQL Command and Execute it
' Create a table
sqlQuery = "CREATE TABLE [log] (website ntext, visitors int)"
cn.execute sqlQuery

Response.write "Script completed."
Set cn = Nothing
%>

Insert rows in table

When the table is ready you can populate it with data (of course you can do this with any editor - Enterprise Manager or SQL Query Analyzer):

' Form SQL Command and Execute it
' Create a table
sqlQuery = "insert into [log] values ('google.com', 10)"
cn.execute sqlQuery

Retreive data from table

Previous two steps were only a prerequsite for the implementation of dynamic chart with ASP and Anychart Flash Chart Component. Let's start it.

Data table is ready and it is populated with data. Now we need file (GetData.asp - Click to launch file on our server and see results), which will exract data from table and present it in XML form.

<data>
<block>
<%

Dim ConnectionString ' SQLServer Connection string
Dim cn' SQLServer Connection object
Dim sqlQuery ' SQL command

Dim RecordSet ' RecordSet Object

' Form a connection string
' Choose ODBC or DSN connection and replace SERVER_NAME, UID, PWD and DB_NAME with real values

'ConnectionString = "driver={SQLServer};server=SERVER_NAME;uid=UID;pwd=PWD;database=DB_NAME" '## MS SQL Server 6.x/7.x/2000 (ODBC connection)
ConnectionString = "Provider=SQLOLEDB;DataSource=TIM\TIM;database=bar;uid=sa;pwd=1;" '## MS SQL Server 6.x/7.x/2000 (OLEDB connection)

' Create and open a connection
set cn = Server.CreateObject("ADODB.Connection")
cn.Open ConnectionString

' Create RecordSet object
Set RecordSet = Server.CreateObject("ADODB.Recordset")
' Form SQL command
sqlQuery = "SELECT website, visitors FROM log"
' Execute query into RecordSet
RecordSet.Open sqlQuery, cn

' Loop through records until the end of RecordSet
while not RecordSet.eof

response.write "<set name=" & chr(34) & RecordSet("website") & chr(34) & " value=" & chr(34) & RecordSet("visitors") &  chr(34) & "/>" & vbcrlf
RecordSet.movenext

wend

Set RecordSet = Nothing
Set cn = Nothing
%>
</block>
</data>

XML output

Now we need file which will store Chart Properties and at the same time contain data (XML.asp - Click to launch file on our server). We left only type selection and some more in this sample to make it clear, actually there are many more settings in AnyChart XML file:

<?xml version="1.0"?>
<root>
  <type>
    <chart type="Horizontal 2DColumn">
        <column_chart block_space="0" column_space="1" left_space="0" right_space="50" up_space="0" down_space="0"/>
    </chart>
    <workspace>
        <chart_area  x="100" y="20"/>
    </workspace>
  </type>

<!--#INCLUDE FILE="GetData.asp"-->

<objects>
    <text text="Created on: <%=now()%>" x= "200" y = "384" auto_size = "yes"/>
</objects>
</root>

Embedding Flash in Html Page

At last, we are just forming a html, containing embedded Flash object (asp.html - Click to launch file on our server):

<html>
<head>
<title>AnyChart ASP 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="650"
height="450"
id="RELEASE"
align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="scale" value="noscale" />

<param name="movie" value="anychart.swf?XMLFile=XML.asp" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />

<embed
src="anychart.swf?XMLFile=XML.asp"
quality="high"
bgcolor="#ffffff"
width="650"
height="450"
name="RELEASE"
align="middle"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer"
scale="noscale"/>
</object>
</body>
</html>

Copyright ©2007 AnyChart.Com All rights reserved.