Use Office Web component to create high-quality charts (1)

Source: Internet
Author: User

When you compile an ASP program, you may need
Indicators are displayed graphically. If only
Is a column chart, you can use the method of drawing a table. Many votes
Most programs use this method. For a pie chart or from data
It is difficult to retrieve the data in the database and display it again.
Alternatively, you can encapsulate EXCEL to complete the above functions, or
Deiphi is used as an activeform input parameter, or PHP
Or Java. Of course, use a relatively mature Image
Components. Microsoft Office Web
Compoent is very good. When I develop a project
This component is used.

Chart. ASP program.

<% Option explicit %>
<! -- # Include file = "adovbs. Inc" -->
<HTML>
<Head>
<Title> bar chart example </title>
<%
Function exportcharttogif (objcspace, strabsfilepath, strrelfilepath)
Dim strfilename
Randomize
Strfilename = timer & RND & ". GIF"
Objcspace. exportpicture strabsfilepath
& "/" & Strfilename, "GIF", 650,400
Exportcharttogif = strrelfilepath
& "/" & Strfilename
End Function

Sub cleanupgif (gifpath)
Dim objfs
Dim objfolder
Dim GIF
Set objfs = server. Createobject ("scripting. FileSystemObject ")
Set objfolder = objfs. getfolder (gifpath)
For each GIF in objfolder. Files
If instr (GIF. Name, ". GIF")> 0 and
Datediff ("N", GIF. datelastmodified, now)> 10 then
Objfs. deletefile gifpath & "/" & GIF. Name, true
End if
Next
Set objfolder = nothing
Set objfs = nothing
End sub

%>
</Head>
<Body bgcolor = "# ffffff">
<Div align = "center">
<Br>
<Br>
<%
Dim sj1, sj2
Sj1 = request. querystring ("S1 ")
Sj2 = request. querystring ("S2 ")

Dim objchartspace
Dim objchart
Dim objseries
Dim objconn
Dim objrs
Dim C
Dim Series
Dim strchartabspath
Dim strchartrelpath
Dim strchartfile
Dim axis

Strchartabspath = server. mappath ("/xjsi-Web/dcss/Chart ")
Strchartrelpath = "/xjsi-Web/dcss/Chart"
'Set the component

Set objchartspace = server. Createobject ("owc. Chart ")
Set objchart = objchartspace. charts. Add
Set c = objchartspace. Constants

Objchartspace. Border. color = "red"
'Display in a bar chart
Objchart. type = 1
Objchart. haslegend = true' whether to display the legend
Objchartspace. haschartspacetitle = true' display title
Objchartspace. chartspacetitle. Caption = "the example of a bar chart uses the Office Web component --www.ourfly.com Chinese technical Website"
Set objconn = server. Createobject ("ADODB. Connection ")
Objconn. open application ("strconn ")
Set objrs = server. Createobject ("ADODB. recordset ")
Set objrs. activeconnection = objconn
Objrs. cursortype = adopenstatic
Objrs. cursorlocation = aduseclient
Objrs. Open "select dwsj, sum (jfr) as jfr
From dcss_do_jfgcfxb where dwsj> = '"& sj1 &"'
And dwsj <'"& sj2 &"'
Group by dwsj order by dwsj ASC"

Set objchartspace. datasource = objrs
'Display the legend content
Objchart. setdata C. chdimseriesnames, 0, "jfr"
For each objseries in objchart. seriescollection
Objseries. setdata C. chdimcategories, 0, "dwsj"
Objseries. setdata C. chdimvalues, 0, "jfr"
Next

For each axis in objchart. Axes
Axis. hastitle = true
If axis. type = C. chcategoryaxis then
Axis. Title. Caption = "month"
Else
Axis. Title. Caption = "people"
End if
Next

Strchartfile = exportcharttogif (objchartspace, strchartabspath, strchartrelpath)
Response. Write "Cleanupgif strchartabspath

Objrs. Close
Set objrs = nothing
Set objconn = nothing
Set objseries = nothing
Set objchart = nothing
Set objchartspace = nothing
%>
</Div>
</Body>
</Html>
Note:
1. On the Office2000 CD, there is an executable file of msowc. MSI. OK
2. We recommend that you use visual interdev6.0 for development. The automatic code prompt function will play a significant role at this time.

As follows:

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.