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.pointsize = 3
Chart.pointstyle = 1
' The last picture is sent to the browser in GIF format
Response.ContentType = "Image/gif"
Response.BinaryWrite Chart.gifline
Response.End
%>
The result is as shown in the figure:
Csdrawgraph's download Address: Http://www.chestysoft.com/download/csdgt.zip