如何使用C#在Excel中添加多个系列的图表 [英] How to add multiple series on a Chart in Excel using C#

查看:1093
本文介绍了如何使用C#在Excel中添加多个系列的图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想补充的图表像下面的图片。

I would like to add a chart like the following picture.

这图有3个系列(黑色,红色,蓝色)。

This chart has 3 series (Black, Red, Blue).

以下是code块,创建一系列在图表上...

The following is a block of code that creates "one" series on a chart...

Excel._Workbook oWorkbook = (Excel._Workbook)oSheet.Parent;
Excel._Chart oChart = (Excel._Chart)oWorkbook.Charts.Add(oSheet, Type.Missing, Type.Missing, Type.Missing);

// Y axis data
Excel.Range oRange = oSheet.get_Range(yRange, Type.Missing);

// Creates a chart
oChart.ChartWizard(oRange, chartType, 2, Excel.XlRowCol.xlColumns, Type.Missing, Type.Missing, false, title, xAxisTitle, yAxisTitle, Type.Missing);

// Sets X axis category
Excel.Series oSeries = (Excel.Series)oChart.SeriesCollection(1);    
oSeries.XValues = oSheet.get_Range(xRange, Type.Missing);
oChart.Name = chartName;

MSDN API是不够的帮助,我很难找到在这个问题上的任何教程或例子。 (或者,也许我不是那么好搜索它们)结果
这将是pciated AP $ P $,如果有人给我一个解决方案。

MSDN API is not helpful enough and I can hardly find any tutorial or example on this problem. (Or maybe I am not that good searching them)
It would be appreciated if someone gives me a solution.

推荐答案

我可以解决这个问题非常简单的解决方案。结果
如果我设置yRange(橙色)的权利,图表向导的方法会自动创建图表。结果
所以代替具有范围的A2:A100,A2:A100,C2:C100的意愿产生一个图表上的两行(系列),并且还如果数据范围包括标题(或串联标签)中,图表向导,将自动把该系列名称中的传奇人物。

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.

这篇关于如何使用C#在Excel中添加多个系列的图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆