Groups | Blog | Home
all groups > asp.net > july 2004 >

asp.net : Anybody has experience with OWC in C#


Edward
7/9/2004 10:35:50 PM
hi, everyone,

I've found many examples of OWC chart, but all are VB version, when I
tried to transform it into C#, compiler told me, "cannot find ChartSpace in
OWC", while the same class can be found in VB version. All the
"import/using" are the same, I'm confused.

Can anybody drop some clue for me? Thanks.

Alvin Bruney [MVP]
7/11/2004 2:56:39 PM
your dataset variable is a bit misleading. the chart cannot bind to datasets
because the chart does not implement Ilistsource. your dataset example
should actually contain a series portion so as not to confuse users.

Also you can use the object browser to find the methods, or follow this link
for a complete interface spec
http://www.webtropy.com/articles/art14-2.asp?Interop=OWC

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
[quoted text, click to view]

Jo Inferis
7/11/2004 7:00:37 PM
[quoted text, click to view]
I'll give it a try (I'm thinking of writing something about my experience
with OWC, little as it is, it still seems to be more than is available on
the web in C#)

What follows is a simple (working) chart example, in C#, which uses OWC.
It's fairly trivial to extend this to use a database or other datasource for
the categories and values (I know, I've done it :)

<code language="C#">
using System;
using System.Web.UI;

//the format of this line is important
using OWC = Microsoft.Office.Interop.OWC;

public class Chart : System.Web.UI.Page
{
private void Page_Load(Object sender, EventArgs e)
{
Response.Buffer = true;
Response.ContentType = "image/gif";

string Categories =
"Jan,Feb,March,April,May,June,July,August,September,October,November,Decembe
r";
string Values = "1,2,3,4,5,6,7,8,9,10,11,12";
int ChartHeight = 400;
int ChartWidth = 400;

OWC.ChSeries DataSet;
OWC.ChChart TheChart;

//create a new chartspace:
OWC.ChartSpace myChartSpace = new OWC.ChartSpace();

//add a chart to it
TheChart = myChartSpace.Charts.Add(0);

//add a dataset to the chart
DataSet = TheChart.SeriesCollection.Add(0);

//name it
DataSet.SetData(OWC.ChartDimensionsEnum.chDimSeriesNames, (int)
OWC.ChartSpecialDataSourcesEnum.chDataLiteral, "OWC DataSet");

//set the dataset plot type
DataSet.Type = OWC.ChartChartTypeEnum.chChartTypeColumnStacked;

//populate it
DataSet.SetData(OWC.ChartDimensionsEnum.chDimCategories, (int)
OWC.ChartSpecialDataSourcesEnum.chDataLiteral, Categories);
DataSet.SetData(OWC.ChartDimensionsEnum.chDimValues, (int)
OWC.ChartSpecialDataSourcesEnum.chDataLiteral, Values);

//set the chart labels
TheChart.HasTitle = true;
TheChart.Title.Caption = "A Simple Chart";
TheChart.Title.Font.Name = "Arial";
TheChart.Title.Font.Size = 8;
TheChart.Title.Font.Bold = true;

TheChart.Axes[0].HasTitle = true;
TheChart.Axes[0].Title.Caption = "Categories";
TheChart.Axes[0].Title.Font.Name = "Verdana";
TheChart.Axes[0].Title.Font.Size = 8;

TheChart.Axes[1].HasTitle = true;
TheChart.Axes[1].Title.Caption = "Values";
TheChart.Axes[1].Title.Font.Name = "Verdana";
TheChart.Axes[1].Title.Font.Size = 8;

//Return the new chart in GIF format.
Response.BinaryWrite((byte[]) myChartSpace.GetPicture("gif", ChartWidth,
ChartHeight));
Response.End();
}
}
</code>

This assumes you've installed the OWC into the GAC successfully (though you
will need to reference the dll when you compile - this may be obvious, but
I've been compiling *everything* by hand and find it's the best way for me
to understand what's going on).

To generate a chart from this, all you have to do is add the compiled
library to the %application%/bin folder and then create an aspx file just
containing "<%@ Page Inherits="Chart" %>" then point your browser at it :)

It's worthwhile having a read of the OWC interop known issues (which
explains the format of the using directive) :

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoxpta/html/odc_piaissues.asp

and having access to something like VB so you can view the object model for
the OWC (actually, if there's a tool out there which allows one to do this
without having to run VB or Visual Studio, I'd love to know...)

HTH!
--
jo inferis

Jo Inferis
7/11/2004 11:40:41 PM
[quoted text, click to view]
Aye, the code was lifted from a current project where DataSet has a
different meaning in the context of the project (which is equivalent to an
OWC.ChSeries). On reflection, it was a bad choice of variable name, I still
think the gist of the program is fairly clear though... (and it does at
least *work*).

[quoted text, click to view]
I'm not entirely sure what you're getting at here, it wasn't intended as an
example of how to populate a chart given a System.Data.DataSet. The
"DataSet" in the example *is* a series. Personally, I'd populate the chart
with a DataReader anyway, it's probably a lot faster.

[quoted text, click to view]
Is there a standalone version of this though (which is what I was asking),
preferably one I can download from somewhere. I don't develop using VS.NET
(it generates too much extraneous code).

[quoted text, click to view]
hmm....lots of broken javascript on that page. It just appears as a long
list of names with no description or signatures...not especially useful :(

I'm fairly happy just running VB for now and using the object browser in
that, but I'd rather run something with a smaller memory footprint (and
shorter loading time).

--
jo inferis

Edward
7/12/2004 8:59:43 AM
Jo Inferis,

Thank a lot !

I've the same experience as yours, I don't use VS.net, just try to do
something by myself, that will help me grasp the Framework.

I've one more question, about difference of VB version and C# version.

Two work versions both have one import line:
<%@ import Namespace="Microsoft.Office.Interop" %>

Your answer reminded me, to add
<%@ import Namespace="Microsoft.Office.Interop.OWC" %> to the C# version,
but I wonder why VB.net version doesn't need this line? It seems to have
automatically find Chart* class from the top level namespace
Microsoft.Office.Interop.

Is there some difference in the two version on looking for classes in
namespace ?

Your answer saved one dll for me, I copied another Interop.OWC10.dll ,
then "Import OWC10" to do the same, but that made me upset.

Edward

----- Original Message -----
From: "Jo Inferis" <inferis@NOSPAM.gotadsl.co.uk>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Monday, July 12, 2004 6:40 AM
Subject: Re: Anybody has experience with OWC in C#


[quoted text, click to view]

Edward
7/12/2004 9:02:43 AM
Alvin, Thank you for your kind answer. It's the second time you helped me.

Do you have any other documents about different chart types, I cannot find
enough materials to guide my step of creating different charts.

Edward

[quoted text, click to view]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoxpta/htm
l/odc_piaissues.asp
[quoted text, click to view]

Alvin Bruney [MVP]
7/12/2004 1:03:16 PM
The best place for that sort of thing would be to download the office web
component tool pack. The different chart types are in there. The code to
create charts are the same. the only thing you need to change is the chart
type. This is true for all chart types with the exception of the 4 or 5
charts which render directly to the chart area and not the plot area
surface. These charts typically do not have defined category/value axes. A
few examples would be bubble, pie and doughnut charts. These charts require
special code.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
[quoted text, click to view]

AddThis Social Bookmark Button