Stacked Column Chart

M

Mike Kelly

We are trying to write code in ASP (VBScript) to generate
a stacked column chart (multiple columns) via a simple
ADO recordset. Does anyone have an example that would be
helpful?

Further explanation: Say you have a "sales" table with
three columns, salesperson, client, and amount. We want
to build a chart that has a stacked column for each
salesperson. As a stacked column chart, the top of the
column will show the total sales while each sale that
makes up the column would be shown in different colors
(stacked).

Here is our code so far: (right now only shows one
record per sales person (first one it comes to in
recordset)).

esponse.Buffer = TRUE
Response.ContentType = "image/gif"

Dim conn, rs
Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB;Data
Source=FBTI1;Initial
Catalog=DADTitleRecorder;UID=sa;password=alpha"

'Execute a query
Set rs = CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM tblBillTest ORDER BY
Abstractor", conn, 3

'Build an array for the ProductName field and an
array for the ProductSales field.
ReDim aClients(rs.RecordCount - 1)
ReDim aPaid(rs.RecordCount - 1)
ReDim aAbstract(rs.RecordCount - 1)
Dim i
Do While Not rs.EOF
aClients(i) = rs.Fields("Client")
aPaid(i) = rs.Fields("Paid")
aAbstract(i) = rs.Fields("Abstractor")
i = i + 1
rs.MoveNext
Loop

'Close the connection to the database.
rs.close
conn.Close
Set rs= Nothing
Set conn = Nothing

'Create a new stacked column chart.
Dim ChartSpace1, Cht, c
Set ChartSpace1 = CreateObject("OWC10.ChartSpace")
Set c = Chartspace1.Constants
Set cht = Chartspace1.Charts.Add
cht.Type = c.chChartTypeColumnStacked
cht.HasLegend = True
cht.HasTitle = True

'Add the data to the chart.
cht.SetData c.chDimSeriesNames, c.chDataLiteral,
aClients
cht.SetData c.chDimCategories, c.chDataLiteral,
aAbstract
cht.SeriesCollection(0).SetData c.chDimValues,
c.chDataLiteral, aPaid

'Format the chart elements.

'Return the new chart in GIF format.
Response.BinaryWrite Chartspace1.GetPicture ("gif",
500, 400)
Response.End
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top