Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Excel.ChartObjects xlCharts = (Excel.ChartObjects)oSheet.ChartObjects(Type.Missing);
                     Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10, 80, 450, 275);
                     oSheet.Shapes.Item("Chart 1").Top = (float)(double)oSheet.get_Range("A15", "A16").Top;
                     Excel.Chart Chart1 = myChart.Chart;
                     Chart1.ChartType = Excel.XlChartType.xlColumnClustered;

                     oRange = oSheet.get_Range("V1", "V15");
                     Chart1.SetSourceData(oRange, Type.Missing);

                     //Set the Chart Title 
                     Chart1.HasTitle = true;
                     Chart1.ChartTitle.Text = "5_lot_yield_trend_B2";


                     //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("A2", "A7");

             
               B2series1.Points(5).Color = System.Drawing.Color.Red; 


Hi. I have a code to plot a bar chart on Excel using c#. However, I want to have a different colour, for example red, for a particular point, say Point 5.
However, I have an error of "invalid parameter - COMException was unhandled" at the line
B2series1.Points(0).Color = System.Drawing.Color.Black


How do I solve this issue? Thank you very much for any help given!

What I have tried:

I've tried changing the series name and added in System.Drawing for references.
Posted
Updated 14-Oct-20 22:58pm

1 solution

The Collection starts at index 1 not 0
 
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