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!