views:

174

answers:

1

I am trying to set the color of individual points in an Excel scatterplot through C#, but can't get it to work. Here is the code I am currently using. Note that the MarkerStyle and MarkerSize part of the code works - so my issue is really about color. I suspect I am missing a cast somewhere.

var point = (Excel.Point)series.Points(index);

point.MarkerStyle = XlMarkerStyle.xlMarkerStyleSquare; point.MarkerSize = 8;

point.MarkerBackgroundColor = 10; point.MarkerForegroundColor = 10;

Thanks in advance for any insight!

+1  A: 

It looks like you are expecting to set a color index rather than an RGB (I say that because you are setting it to 10). I believe MarkerForegroundColor is expecting an RGB color. Did you mean to set MarkerForegroundColorIndex?

Joe Erickson
Thank you so much, you are totally right: a RGB code is expected. I thought this was failing, because the values I was using were too small, and it all looked black to me.The design and/or documentation of this interface is truly perplexing; MarketBackgrounColorIndex is expecting an XlColorIndex, which can take 2 values (automatic or none), so I wonder how one uses the default indexes...
Mathias
The color index properties are indexes into the 56 color palette in Excel. This is a legacy thing - Excel 2003 and previous versions were limited to a 56 color palette. Excel 2007 can handle 24 bit RGB colors so you are better off setting MarkerForegroundColor to the RGB you want if your users will have Excel 2007.
Joe Erickson