Reputation:
I'm trying to change the order of legends (series type legend) in code behind. I have already tried to use the LegendItemOrder property as shown here. But this didn't work out for me.
I also tried to add a custom legend event through code behind as shown here. The custom legend event is added using the below code. But not sure on what arguments to pass with CustomizeLegendEventHandler(arg1, arg2) since the definition has two arguments?
chart.CustomizeLegend += new EventHandler<CustomizeLegendEventArgs> (CustomizeLegendEventHandler);
The event handler definition is shown below.
private void CustomizeLegendEventHandler(object sender, CustomizeLegendEventArgs e)
{
if (e != null)
{
}
}
Please let know what arguments should be passed to CustomizeLegendEventHandler and how to re-order the legend text?
Upvotes: 0
Views: 903
Reputation:
I have identified the answer myself by playing with the code.
Question 1
The custom legend event is added using the below code. But not sure on what arguments to pass with CustomizeLegendEventHandler(arg1, arg2) since the definition has two arguments?
For question 1, the solution is that the event handler can be attached without passing any arguments just like the code shown below.
chart.CustomizeLegend += new EventHandler<CustomizeLegendEventArgs>(CustomizeLegendEventHandler);
You can use the event handler to re-order the legend texts. See the code below.
private void CustomizeLegendEventHandler(object sender, CustomizeLegendEventArgs e)
{
if (e != null && e.LegendItems.Count > 0)
{
e.LegendItems.Reverse();
}
}
The above code will reverse the legend text.
Upvotes: 1