Anybody has experience with OWC in C#

E

Edward

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.
 
J

Jo Inferis

Edward said:
Can anybody drop some clue for me? Thanks.
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!
 
A

Alvin Bruney [MVP]

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
Jo Inferis said:
Edward said:
Can anybody drop some clue for me? Thanks.
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!
 
J

Jo Inferis

Alvin said:
your dataset variable is a bit misleading. the chart cannot bind to
datasets because the chart does not implement Ilistsource.
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*).
your dataset example
should actually contain a series portion so as not to confuse users.
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.
Also you can use the object browser to find the methods
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).
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).
 
E

Edward

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" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Monday, July 12, 2004 6:40 AM
Subject: Re: Anybody has experience with OWC in C#
 
E

Edward

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
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
Jo Inferis said:
Edward said:
Can anybody drop some clue for me? Thanks.
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/htm
l/odc_piaissues.asp
 
A

Alvin Bruney [MVP]

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
Edward said:
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
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
Jo Inferis said:
Edward wrote:
Can anybody drop some clue for me? Thanks.
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/htm
l/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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top