Excel图表comexception未处理 - 参数无效 [英] Excel chart comexception was unhandled - invalid parameter
问题描述
oRange = (Excel.Range)oSheet.Range[oSheet.Cells[2, ypColumn], oSheet.Cells[12, ypColumn]];
Chart1.SetSourceData(oRange, Type.Missing);
//Set the Chart Title
Chart1.HasTitle = true;
Chart1.ChartTitle.Text = "B2 +/- 5 lots Yield Trend (%)";
//Set the y-axis
var B2yaxis = (Excel.Axis)Chart1.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary);
B2yaxis.HasTitle = true;
B2yaxis.AxisTitle.Text = "Yield Percentage";
//Vertical Allignment of y-axis title
B2yaxis.AxisTitle.Orientation = Excel.XlOrientation.xlVertical;
//Set the X-axis
var B2xaxis = (Excel.Axis)Chart1.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary);
B2xaxis.HasTitle = true;
B2xaxis.AxisTitle.Text = "Lot Number";
Excel.SeriesCollection seriescollectionB2 = Chart1.SeriesCollection();
Excel.Series B2series1 = seriescollectionB2.NewSeries();
B2series1.XValues = oSheet.get_Range("B2", "B15");
Excel.SeriesCollection addseriescollectionB2 = Chart1.SeriesCollection();
Excel.Series B2series2 = addseriescollectionB2.NewSeries();
B2series2.XValues = oSheet.get_Range("B7", Type.Missing);
//Horizonal Allignment of x-axis title
B2xaxis.AxisTitle.Orientation = Excel.XlOrientation.xlHorizontal;
//Setting colour of chart
int c = 6;
B2series1.Points(c).Color = (int)Excel.XlRgbColor.rgbRed;
大家好。我有这个代码使用C#在Excel上绘制图形。我创建了一个Excel系列。我想改变那个系列中特定点的颜色。
然而,我在
Hi all. I have this code to plot a graph on Excel, using C#. I created an Excel series. I want to change the color of a particular point in that series.
However, I'm getting an error of "COMException was unhandled - Invalid Parameter" at the line
B2series.Points(c).Color = (int)Excel.XlRgbColor.rgbRed
我不知道如何更改代码。任何帮助将不胜感激。谢谢!
我尝试了什么:
我是尝试添加引用,甚至将代码更改为
I have no idea how to change the code. Any help will be greatly appreciated. Thank you!
What I have tried:
I've tried adding references, and even changing the code to
B2series.Points(c).Color = System.Drawing.Color.Red
推荐答案
这一行:
This line:
B2series.Points(c).Color = (int)Excel.XlRgbColor.rgbRed
建议:)你要改变图表点的颜色。
然后...(VBA版本看起来像)
"suggest" :) that you want to change the color of Point of Chart.
then...(VBA version will look like)
B2series.Points(PointNumber).MarkerBackgroundColor = RGB(0,255,0) ' green
B2series.Points(PointNumber).MarkerForegroundColor = RGB(255,0,0) ' red
B2series.Points(PointNumber).MarkerStyle = xlMarkerStyleCircle ' change the shape
您发布的代码不包含使用B2series
的行。只有B2series1
和B2series2
。
无效参数可能指的是点
索引c
。
Your posted code does not contain a line using theB2series
. There are onlyB2series1
andB2series2
.
The "Invalid parameter" refers probably to thePoint
indexc
.
这篇关于Excel图表comexception未处理 - 参数无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!