Click here to Skip to main content
6,295,667 members and growing! (12,488 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » Miscellaneous Controls     Intermediate

A Charting Custom Control using Microsoft OWC

By Catiger

This is a .NET custom control for web-based charting using Office Web Component technology.
C#, Windows, .NET 1.0, .NET 1.1, GDI+, VS.NET2003, Dev
Posted:9 Sep 2004
Updated:16 Sep 2004
Views:81,941
Bookmarked:39 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
15 votes for this article.
Popularity: 2.74 Rating: 2.33 out of 5
5 votes, 33.3%
1
2 votes, 13.3%
2
2 votes, 13.3%
3
3 votes, 20.0%
4
3 votes, 20.0%
5

Introduction

There are quite a lot commercial or free charting controls available in the market. However, most of the charting requirements are presented with Microsoft Excel charts. In other words, if we can utilize the rich features offered by MS OWC (Office Web Component) including the office charting support, we shall be able to present Microsoft Office charts in web pages.

By employing MS OWC technology, there are basically two approaches to implement the charting control, i.e., server-driven and or client-driven. The server-driven approach is to render the chart at the server side with OWC COM class, through .NET interop. Another one is using OWC ActiveX object. The 2nd approach requires the Office OWC support at the client side and thus incurs the license issue. In this ChartFactory custom control, the server-driven model is adopted. As to how to install the OWC license on the server side, please refer to Microsoft site.

Using the code

Step 1: Adding Control Reference

To use the custom control, you can include the assembly from the toolbox bar in your VS.NET IDE (Add/Remove items -> locate the assembly -> OK). Once done, you can drag and drop that control into ASP.NET forms in any ASPX page or ASCX page.

Step 2: Prepare Chart Data

In order to render the charting, you will have to fill the DataSet first that is required by ChartFactory.AddChartData method. The DataSet instance can only have a single table that must contain three columns having names: "Series", "Group" and "Value". You shall not change the column names as they are referenced by ChartFactory control.

As the ChartFactory doesn't get any chart type information from the DataSet, there shall be some ways to pass the chart type information. It is achieved by passing a parameter ChartFactory.AddChartData method, which however has three types of method signatures:

  • ChartFactory.AddChartData(DataSet dsChart)

    It will choose the DefaultChartType that is set through designer property builder. The chart type will be applied to all series if there are more than one series in the chart.

  • ChartFactory.AddChartData(DataSet dsChart, ChartTypeEnum chartType)

    All series within the chart will have the same chartType.

  • ChartFactory.AddChartData(DataSet dsChart, Hashtable SeriesChartType)

    Each series of the chart may have a different ChartType. Therefore, a mapping between chart series name to chart type are specified in the HashTable.

The ChartFactory.AddChartData method can be called more than once such that more than one chart will be rendered within a single chart space (a term used by MS), and they will all appear in a single GIF image displayed in client HTML.

Render the Chart

Finally, it is to invoke the chart rendering from the application code by calling DataBind() method of the ChartFactory control. The reason why it has to be explicitly invoked is to give more control to the application developers so that they can decide when and where to invoke. Normally, on Page_Load event, ChartFactory.DataBind() has to be called for chart rendering. If there is any postback event, and that would change the DataSet of the ChartFactory or any other properties of it, during the postback event this method will have to be called again.

If any other questions or programming extension requirements, please send to my email box. Thanks. I do all this for the sake of sharing something that can be useful to you.

Appendix: CharTypeEnum Definition

#region CharTypeEnum
 public enum ChartTypeEnum
 {
  Area = 1, /** must start with value=1 as value=0 cause 
               display problem in property browser */
  AreaStacked,
  AreaStacked3D,
  BarStacked,
  Bar3D,
  Column,
  ColumnStacked,
  Column3DStacked,
  Doughnut,
  Line,
  Line3D,
  LineStacked,
  Pie,
  Pie3D,
  PieExploded,
  Pie3DExploded,
  RadarLine,
  ScatterLine
 }
 #endregion

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Catiger


Member
Devoted to IT R&D

8 years of programming experiences

languages: C/C++/VC/C#/java, VB, Delphi

- M.Sc. in Computer Science
- B.Eng in Communication Engineering
Occupation: Web Developer
Location: China China

Other popular Miscellaneous articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 49 (Total in Forum: 49) (Refresh)FirstPrevNext
QuestionSet scaling to secondary Axis. PinmemberBabar Shaik2:48 27 Feb '09  
GeneralWhere Is AIMS.Data.AccessLogic.Common? PinmemberAponilolo14:58 25 Sep '07  
GeneralRe: Where Is AIMS.Data.AccessLogic.Common? PinmemberCatiger17:20 26 Sep '07  
GeneralRe: Where Is AIMS.Data.AccessLogic.Common? PinmemberAponilolo15:15 9 Oct '07  
Generalwhere is AIMS.Data.AccessLogic.Common Pinmemberfengjinzhi15:53 1 Mar '07  
GeneralRe: where is AIMS.Data.AccessLogic.Common PinmemberCatiger17:21 26 Sep '07  
QuestionAdd reference PinmemberEtwanadoo6:50 22 Dec '06  
Questioncan i use this ... Pinmemberkaksx17:28 5 Dec '06  
AnswerRe: can i use this ... PinmemberCatiger17:24 26 Sep '07  
QuestionHelp Needed PinmemberSarma K N23:41 18 Jul '06  
AnswerRe: Help Needed PinmemberCatiger16:54 30 Jul '06  
QuestionGreat Work PinmemberRakhaylo23:43 10 Jun '06  
AnswerRe: Great Work PinmemberCatiger16:59 30 Jul '06  
General.DLL Requested Pinmemberbarodesign23:50 5 Apr '06  
GeneralAccess Denied in ExportPicture Method Pinmemberkkrac4:23 30 Mar '06  
Generalvb .net version? Pinmembertaptu13:28 22 Feb '06  
GeneralDLL needed Pinmembergsdtgzesg17:58 20 Feb '06  
Generalproblem with pie charts Pinmemberkkrac11:11 1 Feb '06  
GeneralRe: problem with pie charts PinmemberCatiger21:42 5 Feb '06  
GeneralRe: problem with pie charts Pinmemberkkrac2:26 6 Feb '06  
QuestionRan into a problem with OWC...wondered if you ever observed this behavior with OWC PinmemberArthur Strutzenberg10:57 17 Jan '06  
AnswerRe: Ran into a problem with OWC...wondered if you ever observed this behavior with OWC PinmemberCatiger22:06 5 Feb '06  
GeneralRe: Ran into a problem with OWC...wondered if you ever observed this behavior with OWC PinmemberArthur Strutzenberg5:44 6 Feb '06  
Generaldll please PinmemberMackerel Catcher22:45 6 Jan '06  
GeneralRe: dll please PinmemberCatiger22:07 5 Feb '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 16 Sep 2004
Editor: Smitha Vijayan
Copyright 2004 by Catiger
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project