Recommended: Tips for using ASP to transfer HTML format data to Excel Learn how to build an ASP page to stream HTML data to an Execl spreadsheet and display the Execl spreadsheet in IE. So far, there are several ways to create Excel data tables using ASP technology, and you can also use server-side Excel 8.0 VBA groups
In our work, we often need to convert data into bar charts, pie charts, etc. to facilitate and intuitive analysis of data. Here I will introduce to you a component that makes pie charts and bar charts in ASP: csDrawGraph, csdgt.zip. Because it is a component, we need to register with REGSVR32.EXE before using it. csDrawGraph, which can create pie charts, bar charts and line charts in ASP. The supported formats include GIF, PNG, JPG and BMP.
chartdemo.asp
| The following is the quoted content: <%@ language=vbscript %> <html> <head> <title>csDrawGraph Demonstration</title> </head> <body bgcolor=#FFFFFF> <P>This simple demonstration shows two graphs using the same data. The first is a bar chart:</P> <P align=center><IMG src=chartimages.asp?Type=Bar width=400 height=300> </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><IMG src=chartimages.asp?Type=Pie width=400 height=300> </P> </body> </html> |
chartimages.asp
| The following is the quoted content: <%@ language=vbscript %> <% Response.Expires = 0 Response.Buffer = true Response.Clear Response.ContentType = Image/Gif Set Chart = Server.CreateObject(csDrawGraphTrial.Draw) Chart.AddData NO> 1, 17, ff0000 Chart.AddData NO> 2, 28, 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 I won't explain it in detail. Let's take a look at an example of converting data from the database to a chart:
lines.asp:
| The following is the quoted content: <html> <head> <title>Line graph showing all the results</title> </head> <body> <table align=center width=400> <tr><td colspan=4><img src=gif_lines.asp width=400 height=300></td></tr> </table> <p>Links to the other result pages:</p> <p><a href=barsbyday.asp>Bar chart showing all results for any one day</a>.</p> <p><a href=barsbycolour.asp>Bar charts showing results for each colour separately</a>.</p> </body> </html> |
gif_lines.asp:
| The following is the quoted content: <%@ language=vbscript %> <% 'Use the data in the database to generate a line graph. 'Create 4 lines according to 4 different values. 'Show 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, and the version will be different. '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 ORDER BY Day 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 'The following sets the component properties 'X-axis 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 image is sent to the browser in GIF format Response.ContentType = image/gif Response.BinaryWrite Chart.GIFLine Response.End %> |
Share: Data operation of ASP rapid development method This is my own experience, for you to refer to. My goal is to make development simple, consider implementation statements as few as possible, and devote more energy to thinking about business logic. I hope my article will inspire and help you. OK, let's get to the point: