Whenever you try to work with more values (labels) on the y axis (bottom) than you have colors you will get this exception. What if it was dynamic though and would just cycle through the colors as many times as needed? I made this change in the Chart base class.
So now you can have many or a few colors and you will never get this color limit exception, it will just cycle through the existing colors. Here's what I did: This was the method giving me the trouble: public Color GetColor(int index) { if (index < _colorLimit)
{ return _color[index]; } else { throw new Exception("Color Limit is " + _colorLimit); } } This method was called everytime a data item (bar or pie) is created. So if you have more pies or bars than colors it would cause an error. I added another function
with the following code: private int _nextColor; // KEEPS TRACK OF WHAT THE NEXT COLOR IS. /// /// Get the next color in the color array. /// public Color GetNextColor() { Color nextColor; // CHECK IF ON LAST COLOR AND RESET TO BEGINNING IF SO. if (_nextColor
> (_color.Length - 1)) _nextColor = 0; nextColor = _color[_nextColor]; _nextColor++; return nextColor; } Now, replace all calls to GetColor with GetNextColor. Now you can truely reuse this component for all different sets of data. Mark
mjmoeykens
Member
10 Points
2 Posts
Tired of "Color Limit is __" exception?
Mar 07, 2004 02:57 AM|LINK