Click here to Skip to main content
15,889,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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;


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
C#
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
Posted
Updated 25-Apr-18 23:12pm

This line:
VB
B2series.Points(c).Color = (int)Excel.XlRgbColor.rgbRed

"suggest" :) that you want to change the color of Point of Chart.
then...(VBA version will look like)
VB
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
 
Share this answer
 
v2
Comments
Member 13650651 26-Apr-18 21:58pm    
How about the C# version? I tried that code but couldn't work.
Your posted code does not contain a line using the B2series. There are only B2series1 and B2series2.

The "Invalid parameter" refers probably to the Point index c.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900