玄铁剑

成功的途径:抄,创造,研究,发明...
posts - 128, comments - 42, trackbacks - 0, articles - 174

ASP.NET Server-Side Charting with OWC11

Posted on 2007-03-13 22:49 玄铁剑 阅读(765) 评论(0)  编辑 收藏 引用 所属分类: Report

Introduction

In Client-Server applications, like public commercial websites and private corporate intranet sites, having graphical reports is a common requirement. Typically, when we have some data projecting the periodical sales figures or the profit and loss margins, it is an obvious use case scenario of having graphical reports summarizing the data over a period.

In such scenarios, if it is a windows application we can have some graphics libraries installed on every machine to generate the charts. Where as in web applications the type of browser and the version being used defines the client capability. Here we will have two options to go for:

  • Client-Side Charting &
  • Server-Side Charting

In client side charting, the client should have a charting engine installed in the machine and a supporting browser. This will help in achieving the client side interactive charting as well as Windows functionality within the browsers. But on the downside, will have complexities in the distribution and setup of the client-side software. And usually license costs per client will increase.

Where as in Server-side charting, only the server needs to have the charting engine installed and the charts can be dynamically generated and streamlined to the client in the form of gif or jpeg. Which is cost effective and any normal browser is sufficient at the client-side. But on the downside, Interactive charting cannot be provided and any change in data or refresh at the client leads to a request to the server and the re-generation of the chart.

This article focuses on the Server side charting in ASP.NET environment. And it also emphasizes on the OWC11 object model and different options for binding data to the chart.

Why OWC?

In ASP.Net Environment we have several ways for generating charts. Some of them are as follows:

  • Using the ASP.Net built-in graphics library (System.Drawing).
  • Using the existing charting engines like,
    • MS-Excel Charting engine
    • Crystal Reports Charting engine
    • Dundas Chart Control for ASP.Net
    • Mycos Charts .Net Web Forms Edition
    • netCharting etc.,

Using the ASP.NET built-in graphics library is the most tedious task and demands a lot of design and implementation effort to be kept in explicitly drawing charts and developing required components.

Coming to the existing charting engines, most of them are pretty expensive and will have a foreign look. Out of these, MS Excel Charting engine is the most widely used and one of the most powerful engines available in the market.

As MS Excel is a widely used application, Microsoft came up with a new idea of providing office like functionality on the web. And this is achieved thru “OWC – Office Web Components” which is the center for our current article.

History

The first version of OWC called OWC9 came with MS-Excel 2000 and MS-Front page 2000. OWC9 came with minimum required charting features that can be used by any web application. Later the next version OWC10 or OWCXP came with MS-Office XP. Though there is no much difference in OWC9 and OWC10, the second version holds some interesting functions for optimizing the performance while generating and saving the charts and some new properties for a better look of charts. And now the latest version OWC11 came with MS-Office 2003. This OWC11 has got some really interesting features like XML support etc.,

Licensing Issues

Regarding the licensing issues of OWC11, we should have license of either MS-Excel 2003 or Front Page 2003. And also when we use OWC11 for client side charting the license is required on both the server and client. Where as, when we use OWC11 for server-side charting, license is required only on the server.

How to Use OWC?

OWC is a COM component holding four ActiveX controls.

  • Spreadsheet control
  • Chartspace control
  • Pivottable control &
  • Datasource control

OWC can be used as either client-side technology by installing it in the client system or as server-side technology by installing only in the server. Coming to the server-side, the core concentration will be on programmatic usage of OWC for generating charts dynamically. Using the OWC Chartspace component, a chart can be generated in the memory of server and can be later streamlined to the client browser as gif or jpeg as a Response to an HTTP Request. So, using OWC11 at server-side only the charting functions, which are of main interest.

Coming to ASP.Net, an OWC11 Interop assembly is required that acts as an RCW (Runtime Callable Wrapper). This Interop assembly can be generated in two ways:

  1. By using the .Net Command Line Utility “Tlbimp”.

Tlbimp owc11.dll /out:Interop.owc11.dll

  1. By using the MS Visual Studio. Net. The .Net IDE creates the wrapper directly when we select the OWC11 COM Component as one of the references for our ASP.Net web application.

Now we have two steps for generating a chart.

First step involves declaring an object of owc11.Chartspace and adding a chart object to the chartspace.charts collection object. Later we can add as many data series as required to the seriescollection object of the chart object. Last but not least we can do some formatting to the Axes, Borders and Interior of the chart as well as to the chartspace and so on.

Second step involves whether saving this chart in a physical Image files like gif or directly streamlining the chart to an Image Control. Saving the chart to a gif file can be done by exporting the chartspace object to the required file at required resolution.

Where as, Streamlining requires a bit of different setting. We have to keep the whole code that generates the chart inside the code-behind of an aspx page that contains no HTML content. Where in, this aspx page can be given as an Image source to an Image control on any other page. Inside this aspx page, after generating the chart, we have to use the GetPicture Method of the Chartspace to push the chart to the Image control directly.

Thus, we can have the charts dynamically generated on the server and pushed to the client. This approach will make the coding part easier, more formatting options and faster generation of the charts.

OWC11 Charting Engine Object Model

In OWC11, the charting engine is exposed out as a Chartspace ActiveX Control. This is something similar to a chart control that comes along with visual studio.

A simplified Chartspace object model will be as follows:

Download Details

The OWC11 is a free download available in the Microsoft website at the below link.

只有注册用户登录后才能发表评论。