Make pie chart, histogram and so on with ASP

Source: Internet
Author: User
Tags sql
Pie chart | Bar Chart | pie chart | Column chart

We often need to transform the data into histogram, pie chart, etc. to facilitate the intuitive analysis of data, here to introduce an ASP to make pie, histogram components: Csdrawgraph,csdgt.zip, because it is a component, So we need to register with REGSVR32.EXE before using, csdrawgraph, you can create pie charts, histogram and line graphs in ASP, its support format has GIF, PNG, JPG and BMP.

Take a look at the following column chart, how pie charts are generated:


Chartdemo.asp

<%@ Language=vbscript%>
<title>csdrawgraph demonstration</title>
<body bgcolor= "#FFFFFF" >
<p>this Simple demonstration shows two graphs using the same data. The IS
A bar chart:</p>
<p align= "center" ></P>
<p align= ' left ' >the second is a pie chart. The background colour is set to light
Grey to show the overall size of the image.</p>
<p align= "center" ></P>
</body>

Chartimages.asp

<%@ Language=vbscript%>

<%
Response.Expires = 0
Response.Buffer = True
Response.Clear
Response.ContentType = "Image/gif"

Set Chart = Server.CreateObject ("Csdrawgraphtrial.draw")


Chart.adddata "No> 1", "ff0000"
Chart.adddata "No> 2", "00FF00"
Chart.adddata "No> 3", 5, "0000FF"

If request.querystring ("Type") = "Pie" Then
Chart.title = "Sample Pie Chart"
Chart.bgcolor = "Eeeeee"
Chart.labelbgcolor = "Eeeeee"
Chart.titlebgcolor = "Eeeeee"
Response.BinaryWrite Chart.gifpie
Else
Chart.title = "Sample Bar Chart"
Response.BinaryWrite Chart.gifbar
End If

Response.End
%>


The program is very simple, and a few more details, here is an example of converting data from a database to a chart:

Lines.asp:

<title>line graph showing all the results</title>

<body>
<table Align=center width=400>
<TR><TD colspan=4></td></tr>
</table>
<p>links to the other result pages:</p>
<p><a Href=barsbyday.asp>bar Chart showing all results to any one day</a>.</p>
<p><a Href=barsbycolour.asp>bar charts showing results for each colour separately</a>.</p>
</body>

Gif_lines.asp:

<%@ Language=vbscript%>
<%
' Generate a line graph using data from a database.
' Generates 4 lines based on 4 different values.
' Displays the name of the week on the x axis.

Response.Expires = 0
Response.Buffer = True
Response.Clear

' Use the following statement to create a chart object with different versions.
' Set Chart = Server.CreateObject (' Csdrawgraph.draw ')
Set Chart = Server.CreateObject ("Csdrawgraphtrial.draw")

ConnectionString = "Provider=microsoft." JET. Oledb.4.0;data source= "& _
Server.MapPath ("Data.mdb")
Set dbconn = Server.CreateObject ("ADODB. Connection ")
Dbconn.open ConnectionString
Set RS = Server.CreateObject ("ADODB.") Recordset ")
SQL = "SELECT * FROM Table1"
Rs. Open SQL, Dbconn

While not RS. Eof
Chart.addpoint CInt (RS ("Day")), CInt (RS ("Red")), "ff0000", "Red"
Chart.addpoint CInt (RS ("Day")), CInt (RS ("Blue"), "0000ff", "Blue"
Chart.addpoint CInt (RS ("Day")), CInt (RS ("green"), "00ff00", "green"
Chart.addpoint CInt (RS ("Day")), CInt (RS ("yellow")), "ffff00", "Yellow"
Chart.addxvalue CInt (RS ("Day")), RS ("Dayname")
Rs. MoveNext
Wend

' Close the database connection
Rs. Close
Dbconn.close

' Set the component properties below
' x coordinates start at 1 instead of 0. (Xoffset = 1)

Chart.title = "All the combined results"
Chart.titlex = 100
Chart.yaxistext = "Total for each day"
Chart.originy = 220
Chart.xoffset = 1
Chart.xtop = 7
Chart.xgrad = 1
Chart.usexaxislabels = True
Chart.linewidth = 2
Chart



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.