How to add multiple series on a Chart in Excel using C#

孤者浪人 提交于 2019-12-03 16:05:58

I could solve this issue with very simple solution.
If I set the yRange (oRange) right, "ChartWizard" method automatically creates the graphs.
So instead of range having "A2:A100", "A2:A100,C2:C100" will generates two lines (series) on one chart and also if the data range includes the heading (or series label), the "ChartWizard" will automatically put the series name in the legend.

I am not too Familiar with C# but you could try something along the lines of

Excel.Range NewRangeObject = oSheet.get_Range(SecondyRange, Type.Missing);        

oChart.NewSeries
oChart.SeriesCollection(2).Name = "New Series"
oChart.SeriesCollection(2).Value = NewRangeObject

To be clear I am kind of guessing based on how the VBA code would look.

A higher level solution is to record a macro in excel directly of setting up the chart exactly the way you want.... then port the Code over to C#. It seems that most of the commands are similiar but wrapped in a slightly different snytax.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!