View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
K Dales[_2_] K Dales[_2_] is offline
external usenet poster
 
Posts: 1,163
Default Dynamic color selection in charts

I have tried this, too - setting chart colors dynamically by some
calculation. The problem is that (for points and lines in charts) Excel uses
the color palette (56 colors only) - if you try to set a different value
Excel will convert it to the closest match in the palette - which is why some
of your colors look the same (or get converted to white).

If you can do with 56 colors, you can use the Colors property of the
workbook to change the palette to a range of colors to your liking. However,
this will change the color selection for many other things in your workbook
as well (such as cell interior colors, etc). The limitations on colors
and/or the effect on the rest of the workbook may cause problems, but I know
of no other solution.

"Anat" wrote:


Hi,

I have an Excel macro that creates a chart with flexible number of
lines (usually up to three lines) and flexible number of points for
each line (may reach 10 points per line). All points and all lines
should be in different colors.
Does someone know of a way to set colors dynamically in a wide color
range that has good distinction between each color?

I tried the following code but when I have many points some colors are
very similar and some are even white.

" Select Case nLineIndex
Case 0:
Select Case nPointIndex
Case 1:
GetPointColor = 3
Case 2:
GetPointColor = 10
Case 3:
GetPointColor = 53
Case 4:
GetPointColor = 39
Case Else:
GetPointColor = nPointIndex* 14 + 1
End Select
Case 1:
Select Case nPointIndex
Case 1:
GetPointColor = 5
Case 2:
GetPointColor = 52
Case 3:
GetPointColor = 46
Case 4:
GetPointColor = 20
Case Else:
GetPointColor = nPointIndex* 10 + 2
End Select
Case 2:
Select Case nPointIndex
Case 1:
GetPointColor = 4
Case 2:
GetPointColor = 13
Case 3:
GetPointColor = 33
Case 4:
GetPointColor = 45
Case Else:
GetPointColor = nPointIndex* 20 + 3
End Select
Case Else:
GetPointColor = nPointIndex* nLineIndex* 10 + nLineIndex
End Select"

Thanks,

Anat


--
Anat
------------------------------------------------------------------------
Anat's Profile: http://www.excelforum.com/member.php...o&userid=16706
View this thread: http://www.excelforum.com/showthread...hreadid=319263