The web poll demo is an illustration of how rChart can be used to display real-time results from a web poll. By real-time, we mean that the data being charted is current as of the reference to the chart page; each time a user revisits or reloads the page, the chart will reflect any updates to an underlying database which have occurred since the last visit or page load.
The web poll demo illustrates several key features of the server component, including use of parameterized queries, text substitution, and streaming output.
To understand this example, the reader should be familiar with asp programming, and have at least a basic understanding of SQL. Also, familiarity with MS Access would be helpful to examine the demo in detail.
The web poll demo is located in the Samples\WebPoll folder of the rChart installation. There are shortcuts to the chart workspace and readme file under rChart|Samples|Web Poll on the Start menu.
The complete web poll demo consists of the following key elements:
Additionally, the demo includes some other pages to add information to the database - to display poll questions and collect results. These pages use the standard ADODB component.
The poll database contains the following tables:
| Name | Purpose |
|---|---|
| Poll | A master list of all polls defined in the database |
| PollQuestion | Contains all poll questions. There is a one:many relationship between this table and Poll; each poll can contain any number of questions. Questions require the user to choose from two or more choices (even if the choices are "Yes" and "No"). |
| PollAnswer | Contains the choices for each question. There is a one:many relationship between this table and PollQuestion; each question can contain any number of choices. |
| PollResponse | Logs each poll submission. Each time getpollinfo.asp is invoked (form submission from webpoll.asp), a new row is added to this table. |
| PollResponseDetail | Provides detail for PollResponse. This table contains one row for each choice indicated in a poll submission. This table, and PollResponse, serve to capture each complete response in a way that could be used to gather statistical detail beyond simply counting how many times a given choice was made for a given question. |
This is the "home" page for the demo. It queries the database for all polls (contents of Poll), and constructs a hyperlink for each poll to webpoll.asp.
This page displays the questions and accompanying choices for a selected poll. It queries Poll in order to display the poll's name at the top of the page, and queries PollQuestion to construct each question. For each question, it also queries PollAnswer to present the choices. Questions and answers are in a form which submits to getpollinfo.asp.
This page is the target of the form submission contained in webpoll.asp. This page logs responses in PollResponse and PollResponseDetail. It also accumulates counts in each of the other tables according to the responses submitted.
This page is used as a "switchboard" for selecting results to be displayed. For a given poll, this page constructs a list of hyperlinks to piechart.asp, one for each question in the poll.
This ASP page constructs a pie chart for a selected poll question using the rChart component and the workspace file pollsample1.fcw.
This rChart workspace defines a pie chart. It uses the User1 substitution parameter (%1) in the title so that the title can be supplied externally. It uses the following parameterized query for obtaining its data:
SELECT PollChoiceText AS "Choice",PollCount AS "Count" FROM PollAnswer WHERE PollQuestionID=:A
The parts of this demo of greatest interest for working with rChart begin with pollresults.asp and the URLs it formulates. A typical URL might look like this:
piechart.asp?A=2&User1=My sample question
When this link is followed, piechart.asp:
Note that aside from using the rChart streaming method, this page does nothing with the response stream, as it would come into conflict with the action of CreateSWFStream.
Copyright © 2002 by rObjects. All rights reserved.