This is a migrated thread and some comments may be shown as answers.

How do I change the order of the legend items in a reporting chart?

3 Answers 265 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Joe asked on 05 Feb 2008, 10:03 PM
I've added several series to a vertical stacked bar chart. The series are displayed on the chart in the reverse order relative to their position in the series collection. On the other hand legend items are displayed in the same order that they are contained in the series collection. I'd like to reverse the order of the items in the legend so that they match the displayed data.

Is there any way for me to change the legend items?

Thanks,
Joe

3 Answers, 1 is accepted

Sort by
0
Accepted
Chavdar
Telerik team
answered on 06 Feb 2008, 04:07 PM
Hello Joe,

The only way to reverse the items in the legend is to populate it manually. Here is a sample code snippet which illustrates the approach:

For Each series As ChartSeries In Me.chart1.Series
    series.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.Nothing
Next

Dim i As Integer = Me.chart1.Series.Count - 1
While i >= 0
    Dim s As ChartSeries = Me.chart1.Series(i)

    Me.chart1.Legend.AddCustomItemToLegend(s.Name, s.Appearance.FillStyle, "Circle")
    System.Math.Max(System.Threading.Interlocked.Decrement(i),i + 1)
End While


Hope this helps.

Best wishes,
Chavdar
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Joe
Top achievements
Rank 2
answered on 08 Feb 2008, 09:38 PM
Thanks,

That worked well. One other thing I had to do was set the series colors manually instead of using a series palette. The modified legend did not automatically pick up the colors from the series palette.
0
Chavdar
Telerik team
answered on 11 Feb 2008, 10:07 AM
Hi Joe,

It is good news that the workaround has helped. As for the problem with the series appearance, it is true that they should be set manually instead of getting them automatically from the series palette. We will put this down as a feature request and will try to implement it in future.

All the best,
Chavdar
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
Joe
Top achievements
Rank 2
Answers by
Chavdar
Telerik team
Joe
Top achievements
Rank 2
Share this question
or