ColorGrid, GridPalette and GetLegendText event
Posted: 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
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