ColorGrid, GridPalette and GetLegendText event

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
SSkov
Newbie
Newbie
Posts: 15
Joined: Thu Nov 23, 2006 12:00 am
Contact:

ColorGrid, GridPalette and GetLegendText event

Post by SSkov » Thu May 03, 2007 8:27 am

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu May 03, 2007 11:26 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

SSkov
Newbie
Newbie
Posts: 15
Joined: Thu Nov 23, 2006 12:00 am
Contact:

Post by SSkov » Thu May 03, 2007 11:46 am

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

Post Reply