Create a new chart in C#

D

davidcjmack

I would like to create a new chart in c#, with each series coming from
a different range.

I have an array of Excel.Range - ranges...

Here's what I have so far:

Excel.Range range = ranges[0];

Excel.Worksheet ws = (Excel.Worksheet)range.Worksheet;
Excel.ChartObjects charts =
(Excel.ChartObjects)ws.ChartObjects(Type.Missing);
Excel.Chart c =
((Excel.ChartObject)charts.Add((double)range.Left, (double)range.Top,
500, 300)).Chart;

chart = c;

Excel.SeriesCollection sc =
(Excel.SeriesCollection)chart.SeriesCollection(Type.Missing);

foreach (Excel.Range r in ranges)
{
Excel.Series series = sc.NewSeries();
series.Values = r;
}


It works - sort of. The chart is created but is invisible. It is
still possible to interact with it though, as control points for series
elements and the draggable handle for the chart itself is present - it
is just invisible!

If I drag it to a new location then it becomes visible.


Where could I be going wrong?


I've tried sc.Add(r,Excel.XlRows, Type.Missing, Type.Missing,
Type.Missing) but got an oleaut 'type mismatch'.

Any help would be greatly appreciated.
 

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

Top