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#?
Figured this one out - when setting the source of the chart information you need to specify the PlotBy
parameter to xlRows
. I was passing in Type.Missing
hence it was defaulting to xlColumns
eg
Excel.ChartObject.SetSourceData(chartRange, Excel.xlRowCol.xlRows);
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.