ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Database Driven Pie CHarts
Posted by Greg on May-03-2010 04:48
How do I create a pie chart for traditional ASP pages that is driven by a database?  Please send me a basic sample code.  Prefer if the pie chart was exploded and 3-D.  Didn't see an example or a reference in the Help manual.  I'm a licensed owner of 3 licenses for 3 different clients of mine.

Thanks.

  Re: Database Driven Pie CHarts
Posted by Peter Kwan on May-03-2010 17:06
Hi Greg,

There are many sample code for 3D pie charts included in ChartDirector. Most of the sample code are using arrays filled with hard coded data. Instead of using hard coded data, you just need to read the data from your database to fill the arrays.

The exact method to read data from your database depends on your database brand and database schema. There are some examples in the section "Using Data Sources in ChartDirector" that show how to read data from a database, and use them to plot charts.

An example is like:

<%
Set cd = CreateObject("ChartDirector.API")

'
' Read data from database
'
SQL = "Select myLabels, myValues From myTable"
Set rs = CreateObject("ADODB.RecordSet")
Call rs.Open(SQL, "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("aaa.mdb"))
Set dbTable = cd.DBTable(rs)
rs.Close()

labels = dbTable.getCol(0)
data = dbTable.getCol(1)

'
'Use the data to plot the chart you like
'

' Create a PieChart object of size 360 x 300 pixels
Set c = cd.PieChart(360, 300)

' Set the center of the pie at (180, 140) and the radius to 100 pixels
Call c.setPieSize(180, 140, 100)

' Draw the pie in 3D
Call c.set3D()

' Set the pie data and the pie labels
Call c.setData(data, labels)

' Output the chart
Response.ContentType = "image/png"
Response.BinaryWrite c.makeChart2(cd.PNG)
Response.End
%>

Hope this can help.

Regards
Peter Kwan