views:

1199

answers:

2

Hi,

I want the series names of the chart to display as the column names of my information. This works when I have more than 1 column however when there is only 1 column of information it seems to set the series name as the number 1.

I reproduced this manually in Excel it seems to assume that the column name is the name of the chart. The way around it seems to go into the "Select Data" option and then select the "Switch Row/Column" option.

Therefore my question is, how can I replicate this option using C#?

A: 

Here's a bit I have in my code to solve the problem. I'm still using Excel 2003. But just in case this helps:

if(Chart.HasTitle)
    Chart.ChartTitle.Text = "";  //Excel put a title on the chart when there's only one series.
Chris Persichetti
Hi, thanks for your answer, however I need to specify a particular title. I am also using Excel 2007. I resolved the issue, please see my answer below.
James
+5  A: 

Hi,

I have resolved this issue myself. When setting the source of the chart information you simply specify the "PlotBy" parameter to xlRows. I was passing in Type.Missing hence it was defaulting to xlColumns.

Excel.ChartObject.SetSourceData(chartRange, Excel.xlRowCol.xlRows);
James
Perfect. Except mine was defaulting to xlRows without the second argument. Passing xlColumns cleared up my issue. Thanks for this!
Jeffrey
Im glad this helped...it was annoying me for ages! I think it defaults to either depending on the chart type :)
James
add me to the list of people who were helped by this, thanks james
hawbsl