How to draw a chart with OWC in asp.net (1)

Source: Internet
Author: User
Tags config modify net command knowledge base visual studio
Asp.net| Chart How to draw a chart with OWC in asp.net (1)

I. Overview

Second, set up the chart engine

III. Licensing issues for OWC

Iv. operating mechanism of OWC

V. Install OWC 10 on the Web server

Six, OWC Programming mode

━━━━━━━━━━━━━

Body:

━━━━━━━━━━━━━

I. Overview

When you develop an application, you often encounter situations where you must provide an interactive diagram. For example, you might be developing an application that manages sales and product data, the data is stored on a SQL Server database, and applications allow users to add data and update existing data, but in addition to these features, customers require applications to visually describe data in the form of pie, column, or xy (scatter) charts.

In Windows desktop applications, such requirements never become a problem, and there are too many graphics libraries and drawing components to choose from. But for Web applications, the problem becomes much more complicated. To draw a chart in a Web application, options include:

Client

With various ActiveX components, it is entirely possible for a Web browser to achieve the functionality of a "rich" Windows client program. The disadvantage is that client-side settings are complicated, requiring the release of client software, which typically calculates the license cost per client basis. In addition, non-MS Windows/ie clients are generally difficult to run.

Server side:

Use the server-side code that runs on the Web server to dynamically generate the chart and send it to the client as a GIF or JPG graphic. The advantage of this approach is that the client only needs a standard browser. The disadvantage of the client-side technology is that the graphics are poorly interactive (you cannot scale, scroll unless you submit a new request to the server). Many map sites (such as mapquest.com) use this technique in large numbers. Note that map graphics are not stored on the Web server, but are generated dynamically from the map database when a user makes a request.

This paper mainly discusses how to use the server-side graph rendering technology to provide graphics function in ASP.net Web pages, specifically, this paper analyzes how to generate a scatter graph by using the data stored in MS SQL database.

Second, set up the chart engine

If you want to draw a chart in a asp.net application, you must have a suitable diagram engine. Asp. NET has a built-in graphics tool library, that is, System.Drawing namespace GDI +, can be used to create simple pie, column, line chart, etc., but it is a low-level API, not to draw the graphics engine, especially not suitable for the drawing of complex charts.

Asp. NET environment there are many commercial chart drawing code base, random search Google, you can find:

Mycos charts. NET Web Forms Edition

Dundas Chart for ASP.net

. netcharting

Charting Controls at the ASP.net control Gallery

However, many of the products are quite expensive and, compared with the world's most widely used charting tool--excel, are a strange sensation. MS Excel is a fairly powerful charting engine that supports a rich range of chart types and provides a complete chart layout adjustment function.

That's why this article is about OWC, the Office Web Components, or the Office Web Component. According to Microsoft's definition, OWC is a "Microsoft technology that extends office-like functionality to the Web." It can be used on a client, such as when we save an Excel worksheet as a Web page, and it makes it easy to publish interactive spreadsheets and charts to a Web page. At the same time, OWC is also an excellent server-side charting engine with the same powerful charting capabilities as MS Excel.

III. Licensing issues for OWC

If you have used an earlier version of OWC, you may have encountered a Microsoft license issue. The problem was so troubling that Microsoft not only required office licenses on the server, but also on every client PC.

In fact, this is equivalent to limiting the use of OWC to an intranet, which guarantees that office licenses are installed on the client's PC. But Microsoft's attitude has slowed down-the server still has office licenses installed, but as long as the chart is "non-interactive", such as the server-side chart drawing for this article, the client will no longer have to install Office licenses. In fact, even the server side does not have to install full office licenses, and Excel 2002 or FrontPage 2002 licenses are sufficient to make OWC a cheap server-side diagram engine.

So, install MS Office on the server? No, it's not necessary. Although OWC should be part of office from a license condition, technically, OWC is a stand-alone product. The OWC software package is only installed on the Web server and you do not have to install entire office.

OWC first appeared in Office 2000, or OWC 9.0. In office XP, OWC's programming mode has been modified, making OWC XP (that is, OWC 10) not fully compatible with OWC 9.0. OWC 10 requires running in a asp.net environment, so the OWC 10 package must be installed on the ASP.net server.

Next, a natural question is: where can i download the OWC 10 package? Surprisingly, it can be downloaded from Microsoft's website free of charge, address is http://office.microsoft.com/downloads/2002/owc10.aspx,
(Chinese address: http://www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&FamilyID= 982B0359-0A86-4FB2-A7EE-5F3A499515DD Internet Prodigal Note) However, it is important to note that a license for Office 2002 must be installed on the Web server to legitimately use OWC 10.

Iv. operating mechanism of OWC

OWC is a collection of COM (ActiveX) controls that cover features such as spreadsheets, charts, PivotTable reports, and so on. It is often used as a client-side technology, when the COM control is installed on the client PC. If used on the server side, people are primarily interested in its charting capabilities.

With OWC, we can dynamically create a chart on the ASP.net Web server, and then send the chart to the client in GIF form. The client sees only a normal graphics file, but in the "back", the graphics file is actually generated dynamically when the ASP.net responds to the client request. As a result, this technique has no special requirements for the client, as long as it can display GIF graphics, even Netscape and opera have no problems.

That being the case, why is OWC's excellent Microsoft technology not yet widely adopted in the ASP.net development field? The fact that Microsoft does not advertise for OWC, coupled with confusing licensing issues, certainly discourages many developers. Perhaps Microsoft believes that the product is not fully mature, the upcoming Office 2003 will bring OWC 11, and its programming model will change. Another possibility is that Microsoft is concerned about the widespread adoption of OWC technologies that can affect office sales.

Furthermore, there are few programming examples about OWC. Microsoft Knowledge Base has several client examples and "traditional" ASP server-side examples, but can not find in the ASP.net environment using OWC 10 example. OWC's newsgroups, microsoft.public.office.developer.web.components, are mainly discussed by client applications. If you want to use the OWC 10 in the ASP.NET environment, the main still is to grope for oneself. Because of these reasons, this paper discusses the practical application of this technique from a fairly wide angle.

V. Install OWC 10 on the Web server

To draw a chart with OWC on a asp.net Web server, you should first install the necessary software and modify some configurations.

First, there should certainly be a asp.net running environment on the Web server. In addition to the. NET Framework redistributable, there is also a gacutil program (the. NET Framework SDK) to configure the OWC control, that is, to install the. NET Framework SDK tool. If the. NET Framework 1.1 Redistributable and SDK are installed to the default directory, the contents of the PATH environment variable should include: C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322; C:\Program Files\microsoft.net\sdk\v1.1\bin.

Next, install OWC 10 on the Web server. OWC can be downloaded from Microsoft free of charge, as long as the installation of all the default options can be used.

Since OWC 10 is a COM technology, in order to let. NET code uses the OWC 10 component, you must also have the primary Interop Assembly (PIA) for Office XP installed, and the PIA can be downloaded from the Microsoft Web site (http://msdn.microsoft.com/library/ default.asp?url=/library/en-us/dnoxpta/html/odc_oxppias.asp).
(Internet prodigal Son found the address is: http://www.microsoft.com/downloads/details.aspx?) familyid=c41bd61e-3060-4f71-a6b4-01feba508e52&displaylang=en)
The downloaded OXPPIA.exe is a compressed file, now unzip it to a directory on the server, assuming it is C:\oxppia, and then start a command window (note that make sure the PATH environment variable is set correctly [ Internet Prodigal Note: You can run it with my setpath.bat], go to the C:\oxppia directory, run Register.bat.

This command imports the Office XP PIA into the global assembly buffer and modifies registry settings. Notice the output of the Register.bat command, and be sure that the gacutil command is actually running. If the PATH environment variable is set incorrectly, the PIA cannot be imported correctly. The Readme document says that you should use the Vs.net command-line environment, but you may not have Vs.net installed on the Web server, and you will have to manually modify the PATH environment variable (the same effect).

Finally, add the following line of code to the <assemblies> section of the Web server's Machine.config file, for the. NET Framework 1.1,machine.config files can be C:\WINDOWS\ Microsoft.net\framework\v1.1.4322\config Directory found:


<add assembly= "Microsoft.Office.Interop.OWC, version=10.0.4504.0,
Culture=neutral, publickeytoken=31bf3856ad364e35 "/>


Prodigal Note: If there are errors that cannot be compiled, you may want to run the registration step again! I like this, everyone if not the same, you can try.

Six, OWC Programming mode

To display a OWC chart in the ASP.net page, we'll create a simple asp.net page that is designed to display the chart. The name of the Web page is getchart.aspx. To display a chart in a Web page, you can use a standard HTML tag, as follows:









The Getchart.aspx page dynamically generates OWC charts on the server, and then converts the chart to a GIF graphic to the client. As a result, in the client's view, getchart.aspx is equivalent to a GIF graphic.

Below we analyze the getchart.aspx file. If you use the ASP.net codebehind mechanism, getchart.aspx actually takes a few asp.net instructions:



<%@ Page language= "vb" autoeventwireup= "false"
Codebehind= "Getchart.aspx.vb" inherits= "Getchart"%>
<%@ OutputCache duration= "5" varybyparam= "None"%>




The data sources to generate the chart are called the data source, and the Chart component component supports any data source that implements the IDataSource interface, an ADO Recordset object, an XML file, an array, or a text string of a certain format. In ASP, we can use the ADO Recordset object; NET in Ado.net, because Ado.net did not implement Idatasource,.net nor did it provide a direct conversion of the Ado.net DataSet object to the ADO Recordset object, if you have a DataSet object, You can either convert to an XML file or generate a specially formatted string to use. The following is the result of this example:



[Prodigal Note: If error, may be the problem of folder permissions, I am, to the virtual directory of everyone's permissions Plus! ]



The following is a vb.net version of the ASP.net example and code that implements this functionality:

Owc.aspx:

<%@ Page language= "vb" autoeventwireup= "false" codebehind= "OWC.aspx.vb" inherits= "ASPXWEB.OWC"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name= "generator" content= "Microsoft Visual Studio 7.0" >
<meta name= "Code_language" content= "C #" >
<meta name= "vs_defaultClientScript" content= "JavaScript" >
<meta name= "vs_targetschema" content= "http://schemas.microsoft.com/intellisense/ie5" >
<body ms_positioning= "GridLayout" >
<form id= "Form1" method= "POST" runat= "Server" >
<asp:placeholder id= "Chartholder" runat= "Server" ></asp:placeholder>
</form>
</body>
</HTML>


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.