C# .NET - <Urgent>: C# : Help Required: Using OWC to generate Charts in c#

Asked By harry g on 10-Sep-09 11:28 AM

Hi .net gurus, 

I have requirement to generate Bar/column charts in my asp.net application for the data i am retrieving from database.

I have to make use of 'Series' same as in charts we generate excel.

I tried with below code, but i am getting only single bar for the series 'Volume1' below, , any pointers as to what is wrong in here....

I am using the code that i have got from VelocityViews....pasted below

-------------------------------

Response.Buffer = true;

Response.ContentType = "image/gif";

string Categories ="Jan,Feb,March,April,May,June,July,August,Septembe r,October,November,December";

string Values = "1,2,3,4,5,6,7,8,9,10,11,12";

string Values1 = "5,6,7,8,9,10,11,12,13,14,15,16";

int ChartHeight = 400;

int ChartWidth = 400;

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 DataSeries to the chart

OWC.ChSeries DataSeries = TheChart.SeriesCollection.Add(0);

//name it

DataSeries.SetData(OWC.ChartDimensionsEnum.chDimSeriesNames,(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, "OWC DataSet1");

//set the DataSeries plot type

DataSeries.Type = OWC.ChartChartTypeEnum.chChartTypeColumnStacked;

//populate it

DataSeries.SetData(OWC.ChartDimensionsEnum.chDimCategories, (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, Categories);

DataSeries.SetData(OWC.ChartDimensionsEnum.chDimValues, (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, Values);


OWC.ChSeries DataSeries2 = TheChart.SeriesCollection.Add(1);

DataSeries2.Type = OWC.ChartChartTypeEnum.chChartTypeColumnStacked;

//DataSeries2.SetData(OWC.ChartDimensionsEnum.chDimSeriesNames, (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, "OWC DataSeries2");

DataSeries2.SetData(OWC.ChartDimensionsEnum.chDimCategories, (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, Categories);

DataSeries2.SetData(OWC.ChartDimensionsEnum.chDimValues, (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, Values1);

//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();

-------------------------------

Basically my real data would look something like below, each column repesenting an year..

Jan 111,111 543,638 5454,65
Feb
184,643
426,187
782,336
Mar
268,821
555,944
487,132
Apr
207,464
458,480
789,421
May 484,766 441,417 444,421
June 416,926 504,586 653,321

Folks, Am badly waiting for help, do let me know if any other info is requried

Thanks






Few things. - [)ia6l0 iii replied to harry g on 10-Sep-09 12:06 PM

1. Set the chart type before setting up the series.

Instead of this:
DataSeries.SetData(OWC.ChartDimensionsEnum.chDimSeriesNames,(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, "OWC DataSet1");
DataSeries.Type = OWC.ChartChartTypeEnum.chChartTypeColumnStacked;

Write like:
DataSeries.Type = OWC.ChartChartTypeEnum.chChartTypeColumnStacked;
DataSeries.SetData(OWC.ChartDimensionsEnum.chDimSeriesNames,(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, "OWC DataSet1");

2. Is it mandatory to set the chart series type too, even after you set the chart type. I find the following line not so useful. However, look at the documentation of OWC to confirm that.
Chart1_Series1.Type = Chartspace1.Constants.chChartTypeScatterLineMarkers
Look at a similar example http://www.csharphelp.com/archives2/archive457.html. 

HTH.

C# : Creating charts Using OWC - harry g replied to [)ia6l0 iii on 11-Sep-09 05:11 AM

Thanks Bro !! You saved my day....

Commenting out the following lines did the trick

DataSeries.Type = OWC.ChartChartTypeEnum.chChartTypeColumnStacked;

DataSeries1.Type = OWC.ChartChartTypeEnum.chChartTypeColumnStacked;

Am able to pretty much get things going, but stuck at following issues.  Will keep working on that, but in case you know something on this, please pass on the information...

1. Can I Have the tooltip on the bars that get generated. I know when it gets displayed, its a gif image, but is there a way to have a tooltip, so that hovering on the bar would show its value to the user.

2.  Can we decrease / increase width of the bar, or give a kind of a gap between the bars in a series