Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Create Excel chart using C#

2 views
Skip to first unread message

Sashi

unread,
Apr 24, 2003, 2:23:43 AM4/24/03
to
Hi,

This is what I am trying to do.
1. Launch Excel Application
2. Create Workbook
3. Add Data to Worksheet
4. Add Chart which uses above data

step 1,2,3 are working fine.
I could not find much documentation on step 4 above.
I am trying Workbook.Charts.Add(). Is there any good
documentation or sample C# code for this?

thanks,
Sashi

Peter Torr (MS)

unread,
Apr 27, 2003, 10:01:35 PM4/27/03
to
"Sashi" <yeno...@hotmail.com> wrote in message
news:057701c30a2a$0e130ea0$a401...@phx.gbl...

> I could not find much documentation on step 4 above.
> I am trying Workbook.Charts.Add(). Is there any good
> documentation or sample C# code for this?

Hi,

I copied this straight out of the Visual Studio Tools for Office help file:


// ---------
public void CreateChart()
{
Excel.Worksheet thisWorksheet;
thisWorksheet = thisWorkbook.ActiveSheet as Excel.Worksheet;
Excel.ChartObjects charts =
(Excel.ChartObjects)this.thisWorksheet.ChartObjects(Type.Missing);

// Adds a chart at x = 100, y = 300, 500 points wide and 300 tall.
Excel.ChartObject chartObj = charts.Add(100, 300, 500, 300);
Excel.Chart chart = chartObj.Chart;

// Gets the cells that define the bounds of the data to be charted.
Excel.Range chartRange = this.thisWorksheet.get_Range("A5","D8");
chart.SetSourceData(chartRange,Type.Missing);

chart.ChartType = Excel.XlChartType.xlXYScatter;
Excel.SeriesCollection seriesCollection=
(Excel.SeriesCollection)chart.SeriesCollection(Type.Missing);
Excel.Series series = seriesCollection.Item(seriesCollection.Count);
}

//----------

Peter

--
Please post questions to the newsgroup - everyone benefits.
This post is provided "AS IS" with no warranties, and confers no rights
Sample code subject to http://www.microsoft.com/info/cpyright.htm


0 new messages