Page 1 of 1

ColorGrid, GridPalette and GetLegendText event

Posted: Thu May 03, 2007 8:27 am
by 9643156
Hello,

I am using a ColorGrid series and GridPalette entries to show a plot of color codes. To have the legend show the description for each color, I use the LegendStyle.Palette and handle the GetLegendText event.

Now, my problem is that I have a hard time matching the description text with the correct color. In the GetLegentText event handler I use the Index member of the GetLegendTextEventArgs argument, but as far as I can see the index does not correspond to the order in which I added the palette entries to the ColorGrid series:

// Setup palette...
_seriesColorGrid.Palette.Clear();
_seriesColorGrid.Palette.Add( new GridPalette( 0.0f, Color.Magenta ) );
_seriesColorGrid.Palette.Add( new GridPalette( 1.0f, Color.Blue ) );
_seriesColorGrid.Palette.Add( new GridPalette( 2.0f, Color.Green ) );
_seriesColorGrid.Palette.Add( new GridPalette( 3.0f, Color.Red ) );
_seriesColorGrid.Palette.Add( new GridPalette( 4.0f, Color.Yellow ) );

...

// The GetLegendText event handler...
private void _chart_GetLegendText( object sender, GetLegendTextEventArgs e )
{
e.Text = _resourceManager.GetString( "FlowReg" + e.Index.ToString() );

}


In the GetLegendText event handler I assumed that e.Index = 0 would indicate the first GridPalette entry (color = Magenta), but it seems to actually indicate the last entry (color = Yellow). As I investigated further it seemed that the indexes I get in the event handler matches my color entries in reverse order.

My questions are: Is this by design, or is it just a coincidence? Am I handling the indexes/colors in an unsafe way? Should I take a whole new approach, or is it safe to simply do "FlowReg" + (NumPaletteEntries-e.Index-1).ToString() instead?


Regards
Steffen Skov
Senior Consultant
SPTGroup

Posted: Thu May 03, 2007 11:26 am
by narcis
Hi Steffen,

Code: Select all

My questions are: Is this by design, or is it just a coincidence? Am I handling the indexes/colors in an unsafe way? Should I take a whole new approach, or is it safe to simply do "FlowReg" + (NumPaletteEntries-e.Index-1).ToString() instead? 
This is by design. Unless you are changing which items are displayed in the legend it seems fine to me. I would try using the approach you suggest.

Posted: Thu May 03, 2007 11:46 am
by 9643156
Hi NarcĂ­s,

thank you for your quick response. Hopefully I can now rest assured that my solution will not suddenly break as a result of bug-fixes in the future. 8)

Regards

Steffen Skov
Senior Consultant
SPTGroup