'Excel VSTO C# change Marker fill color of Chart series always apply only 1 color to multiple series
I am trying to change Marker Fore Color of series 4 and 6 to two different colors, but somehow they have the same color. Please kindly advice
series1.Format.Line.ForeColor.RGB = (int)(0x000000);
series2.Format.Line.ForeColor.RGB = (int)(0xFF0000);
series3.Format.Line.ForeColor.RGB = (int)(0xA9D18E);
series4.Select();
series4.Format.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
series4.MarkerStyle = XlMarkerStyle.xlMarkerStyleAutomatic;
series4.Format.Fill.ForeColor.RGB = (int)(0x0000FF);
series4.Format.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
series4.Format.Fill.Solid();
series5.Select();
series5.Format.Line.ForeColor.RGB = (int)(0x9609ED);
series6.Select();
series6.Format.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
series6.MarkerStyle = XlMarkerStyle.xlMarkerStyleAutomatic;
series6.Format.Fill.ForeColor.RGB = (int)(0xED7D31);
series6.Format.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
series6.Format.Fill.Solid();
I also generate VBA macro from Excel (for comparing), the macro will only turns 2 series from Lines to no-line and change Marker color only. This macro works.
Sub Macro1()
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.FullSeriesCollection(5).Select
Selection.Format.Line.Visible = msoFalse
Selection.MarkerStyle = -4105
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent2
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.25
.Transparency = 0
.Solid
End With
ActiveChart.FullSeriesCollection(2).Select
Selection.Format.Line.Visible = msoFalse
Selection.MarkerStyle = -4105
Selection.Format.Line.Visible = msoFalse
Selection.Format.Line.Visible = msoFalse
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent5
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.25
.Transparency = 0
.Solid
End With
End Sub
Updated Solution: I found solution, even not sure why it is: just change order of the statement as below
series6.Select();
series6.Format.Line.Visible =
Microsoft.Office.Core.MsoTriState.msoFalse;
series6.MarkerStyle = XlMarkerStyle.xlMarkerStyleAutomatic;
series6.Format.Fill.Visible =
Microsoft.Office.Core.MsoTriState.msoTrue;
series6.Format.Fill.Solid();
series6.Format.Fill.ForeColor.RGB = (int)(0xED7D31);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|