Pie charts use charts (chart) to represent data in a Web page
One of the things that you often need to do in WEB programming is to display the data (numbers) that are detected from the database in the form of a chart (chart). Here's a quick summary of several common practices.
1. If the style of the chart only needs a column chart (bar), there is a very simple, lazy way, that is, using some of the tag's width property to perform. Examples are as follows:
src=http://www.163design.net/a/q/"small squares. gif" >
With this kind of thinking, if not too ugly, you simply use for loop control * Number of the display number is also not possible. ;-)
If you want to be more beautiful, you can design a good CSS, and then combine with DHTML.
A complete example of this method is shown in:
Http://www.microsoft.com/workshop/database/datavis/datavis.asp
2. Some guys like to put pictures directly in the database, so let's see how to tune them out.
(If these pictures are just graphs, I'm not straying.) ;-))
This is an example of the online Help for IIS:
Http://localhost/IIsSamples/SDK/asp/docs/CodeBrws.asp?source=/IIsSamples/SDK/asp/Database/Blob_VBScript.asp
Its core code:
<%
' The declaration is a Gif file, not an ordinary HTML
Response.Buffer = TRUE
Response.ContentType = "Image/gif"
' Even database
Set oconn = Server.CreateObject ("ADODB. Connection ")
oConn.Open "Dsn=localserver; Uid=sa; pwd=;D Atabase=pubs "
' Find a good picture
Set oRs = Oconn.execute ("Select logo from pub_info WHERE pub_id= ' 0736 '")
' Take the value to appear professional;-
Picsize = ORs ("logo"). ActualSize
Pic = ORs ("logo"). GetChunk (Picsize)
' Again, it's a GIF picture, and view source doesn't see anything.
Response.BinaryWrite Pic
Response.End
%>
Well, look at the notes, man (I don't have a good habit;-) asks: This program mypic.asp the final effect in the browser
Equivalent to Mypic.gif, I want to have words to do?
Quite simply, writing a Web page with is not over. ;-)
3. Also some of the older man, these heroes of the machine is mostly 8 CPU P III, they use the Server-side software,
Excel, for example, now makes a chart picture and then passes it to the browser in GIF format. More in the CGI master. ;-)
Let's look at a cool demo like this.
Core code:
<%
Set Excel = GetObject ("", "Excel.Application")
If err.number <> 0 Then
Response.Write ("Could not create Excel document." + err.description+ "")
Err.Clear
End If
Excel. DisplayAlerts = False
Set workbooks = Excel. Workbooks
Set wb = Workbooks. Add
Set sheets = wb. Sheets
Set wstotal = sheets. ADD (,,,-4167)
Wstotal.name = "Total_expenses"
Set range = Wstotal.range ("B1")
Range. FORMULAR1C1 = "1"
Set range = Wstotal.range ("C1")
Range. FORMULAR1C1 = "2"
Set range = Wstotal.range ("D1")
Range. FORMULAR1C1 = "3"
Wstotal.activate
Wstotal.select
Set range = Wstotal.range ("B1:d1")
Excel. Charts.add
Excel. Activechart.charttype = 51
Excel. Activechart.setsourcedata range,2
Excel. Activechart.export "D:\test\exceltest" + ". gif", "GIF"
Response.Write "%>
Real lazy people in writing this code also use Excel VBA (:-P), absolute code fast shooter, but the efficiency----pooh! ;-)
4. Well, it's time to take a look at the professional athlete's approach----use chart control.
What kind of control is better everyone has a different opinion, (for example, some guys like Java Applets;-) And some of the guys like to use C + + for their own development) for simplicity, here I recommend Microsoft (;-))----Office Web Component. ;-)
In the previous article I introduced several ways in which controls and data were combined, and we analyzed how the chart control in Excel 2000 was implemented.
A. Row-by-line assignment
Excel Chart Control has two methods of assignment: An array, a string.
Array method:
code example:
----------------------------------
<object Id=chartspace1 classid=clsid:0002e500-0000-0000-c000-000000000046 style= "width:100%;height:350" > </object>
<script language=vbs>
Sub Window_onload ()
Dim categories (3), VALUES (3)
' 4 categories
Categories (0) = "White"
Categories (1) = "BLACK"
Categories (2) = "Asian"
Categories (3) = "Latino"
' Preparation activities;-
ChartSpace1.Clear
ChartSpace1.Charts.Add
Set C = chartspace1.constants
' Add a value of three series
Chartspace1.charts (0). SeriesCollection.Add
Chartspace1.charts (0). SeriesCollection.Add
Chartspace1.charts (0). SeriesCollection.Add
' Icing on the cake;-]
Chartspace1.charts (0). SeriesCollection (0). Caption = "Perot"
' Set
Chartspace1.charts (0). SeriesCollection (0). SetData c.chdimcategories, C.chdataliteral, categories
VALUES (0) = 0.2 ' The white value.
VALUES (1) = 0.06 ' The black value.
VALUES (2) = 0.17 ' The Asian value.
VALUES (3) = 0.13 ' the Latino value.
Chartspace1.charts (0). SeriesCollection (0). Caption = "Perot"
Chartspace1.charts (0). SeriesCollection (0). SetData c.chdimcategories, C.chdataliteral, categories
Chartspace1.charts (0). SeriesCollection (0). SetData c.chDimValues, C.chdataliteral, values
' Series two contains election data for Clinton.
' Update the values array, then set the chart data.
VALUES (0) = 0.38 ' The White