Click here to Skip to main content
12,503,681 members (31,545 online)
Click here to Skip to main content
Add your own
alternative version

Stats

126.8K views
1.8K downloads
40 bookmarked
Posted

A Charting Custom Control using Microsoft OWC

, 15 Sep 2004
Rate this:
Please Sign up or sign in to vote.
This is a .NET custom control for web-based charting using Office Web Component technology.

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

Share

About the Author

Catiger
Web Developer
China China
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

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionSpace between each bars Pin
maajanes13-Aug-12 2:50
membermaajanes13-Aug-12 2:50 
QuestionSet scaling to secondary Axis. Pin
Babar Shaik27-Feb-09 1:48
memberBabar Shaik27-Feb-09 1:48 
QuestionWhere Is AIMS.Data.AccessLogic.Common? Pin
Aponilolo25-Sep-07 13:58
memberAponilolo25-Sep-07 13:58 
AnswerRe: Where Is AIMS.Data.AccessLogic.Common? Pin
Catiger26-Sep-07 16:20
memberCatiger26-Sep-07 16:20 
GeneralRe: Where Is AIMS.Data.AccessLogic.Common? Pin
Aponilolo9-Oct-07 14:15
memberAponilolo9-Oct-07 14:15 
Generalwhere is AIMS.Data.AccessLogic.Common Pin
fengjinzhi1-Mar-07 14:53
memberfengjinzhi1-Mar-07 14:53 
GeneralRe: where is AIMS.Data.AccessLogic.Common Pin
Catiger26-Sep-07 16:21
memberCatiger26-Sep-07 16:21 
QuestionAdd reference Pin
Etwanadoo22-Dec-06 5:50
memberEtwanadoo22-Dec-06 5:50 
Questioncan i use this ... Pin
kaksx5-Dec-06 16:28
memberkaksx5-Dec-06 16:28 
AnswerRe: can i use this ... Pin
Catiger26-Sep-07 16:24
memberCatiger26-Sep-07 16:24 
QuestionHelp Needed Pin
Sarma K N18-Jul-06 22:41
memberSarma K N18-Jul-06 22:41 
AnswerRe: Help Needed Pin
Catiger30-Jul-06 15:54
memberCatiger30-Jul-06 15:54 
QuestionGreat Work Pin
Rakhaylo10-Jun-06 22:43
memberRakhaylo10-Jun-06 22:43 
AnswerRe: Great Work Pin
Catiger30-Jul-06 15:59
memberCatiger30-Jul-06 15:59 
General.DLL Requested Pin
barodesign5-Apr-06 22:50
memberbarodesign5-Apr-06 22:50 
GeneralAccess Denied in ExportPicture Method Pin
kkrac30-Mar-06 3:23
memberkkrac30-Mar-06 3:23 
Questionvb .net version? PinPopular
taptu22-Feb-06 12:28
membertaptu22-Feb-06 12:28 
GeneralDLL needed Pin
gsdtgzesg20-Feb-06 16:58
membergsdtgzesg20-Feb-06 16:58 
Generalproblem with pie charts Pin
kkrac1-Feb-06 10:11
memberkkrac1-Feb-06 10:11 
GeneralRe: problem with pie charts Pin
Catiger5-Feb-06 20:42
memberCatiger5-Feb-06 20:42 
GeneralRe: problem with pie charts Pin
kkrac6-Feb-06 1:26
memberkkrac6-Feb-06 1:26 
QuestionRan into a problem with OWC...wondered if you ever observed this behavior with OWC Pin
Arthur Strutzenberg17-Jan-06 9:57
memberArthur Strutzenberg17-Jan-06 9:57 
AnswerRe: Ran into a problem with OWC...wondered if you ever observed this behavior with OWC Pin
Catiger5-Feb-06 21:06
memberCatiger5-Feb-06 21:06 
GeneralRe: Ran into a problem with OWC...wondered if you ever observed this behavior with OWC Pin
Arthur Strutzenberg6-Feb-06 4:44
memberArthur Strutzenberg6-Feb-06 4:44 
Generaldll please Pin
Mackerel Catcher6-Jan-06 21:45
memberMackerel Catcher6-Jan-06 21:45 
GeneralRe: dll please Pin
Catiger5-Feb-06 21:07
memberCatiger5-Feb-06 21:07 
GeneralWhere is using AIMS.Data.AccessLogic.Common; Pin
renyu73217-Dec-05 16:42
memberrenyu73217-Dec-05 16:42 
GeneralDLL Pin
Your details have been updated21-Sep-05 22:08
sussYour details have been updated21-Sep-05 22:08 
GeneralDLL & Source Code Requested Pin
fago-de-chao12-Aug-05 14:44
memberfago-de-chao12-Aug-05 14:44 
GeneralDLL Requested Pin
alirezakhan8-May-05 22:12
memberalirezakhan8-May-05 22:12 
General,.DLL Version Pin
alirezakhan7-May-05 22:04
memberalirezakhan7-May-05 22:04 
General.DLL Version Pin
alirezakhan7-May-05 22:06
memberalirezakhan7-May-05 22:06 
GeneralRe: .DLL Version Pin
sampahgua19-Jun-05 16:07
susssampahgua19-Jun-05 16:07 
GeneralRe: .DLL Version Pin
mfigueiroa12-Dec-06 16:10
membermfigueiroa12-Dec-06 16:10 
GeneralCompiled Version Pin
BUXjr5-May-05 3:46
memberBUXjr5-May-05 3:46 
GeneralRe: Compiled Version Pin
Catiger5-May-05 15:33
memberCatiger5-May-05 15:33 
GeneralRe: Compiled Version Pin
BUXjr5-May-05 15:36
memberBUXjr5-May-05 15:36 
GeneralRe: Compiled Version Pin
Catiger6-May-05 1:41
memberCatiger6-May-05 1:41 
GeneralRe: Compiled Version Pin
BUXjr6-May-05 1:47
memberBUXjr6-May-05 1:47 
GeneralRe: Compiled Version Pin
Catiger9-May-05 21:26
memberCatiger9-May-05 21:26 
GeneralRe: Compiled Version Pin
Rajesh_K_Sharma11-May-06 23:08
memberRajesh_K_Sharma11-May-06 23:08 
GeneralRe: Compiled Version Pin
Rajesh_K_Sharma11-May-06 23:09
memberRajesh_K_Sharma11-May-06 23:09 
GeneralPie Chart Pin
Anonymous26-Apr-05 0:00
sussAnonymous26-Apr-05 0:00 
GeneralRe: Pie Chart Pin
catigerman26-Apr-05 14:47
susscatigerman26-Apr-05 14:47 
Generaldoes't work Pin
eliseoroap6-Apr-05 7:50
membereliseoroap6-Apr-05 7:50 
GeneralRe: does't work Pin
Catiger6-Apr-05 23:59
memberCatiger6-Apr-05 23:59 
Generalseries & Group Pin
Anonymous29-Mar-05 22:55
sussAnonymous29-Mar-05 22:55 
QuestionSample? Pin
melcolm8-Mar-05 11:56
membermelcolm8-Mar-05 11:56 
AnswerRe: Sample? Pin
Catiger9-Mar-05 3:16
memberCatiger9-Mar-05 3:16 
GeneralImage Pin
Smitha Vijayan15-Sep-04 21:55
staffSmitha Vijayan15-Sep-04 21:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160919.1 | Last Updated 16 Sep 2004
Article Copyright 2004 by Catiger
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid