ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Charts and Charting in Excel (https://www.excelbanter.com/charts-charting-excel/)
-   -   Create a new chart in C# (https://www.excelbanter.com/charts-charting-excel/101568-create-new-chart-c.html)

[email protected]

Create a new chart in C#
 
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(Typ e.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.



All times are GMT +1. The time now is 12:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com