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

Stacked bars legend

3 Answers 81 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Travis
Top achievements
Rank 1
Travis asked on 19 Sep 2008, 11:12 PM
When I created stacked bars chars the legend is always reverse to what the order of the stacked bars are.  Is there any way to achieve the legend matching to colors of the stacked bar?

3 Answers, 1 is accepted

Sort by
0
Accepted
Ves
Telerik team
answered on 23 Sep 2008, 07:18 AM
Hello Travis,

This is the expected behavior as the bars are stacked from the bottom towards the top, while the legend items are added top to bottom. You can wire BeforeLayout event of the chart and reorder the RadChart.Legend.Items collection.


All the best,
Ves
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Travis
Top achievements
Rank 1
answered on 23 Sep 2008, 06:37 PM
Here is a code snippet if anyone else runs across this.

    Protected Sub reverseLegend(ByRef collection As Telerik.Charting.ChartLabelsCollection) 
        Dim temp(collection.Count - 1) As Telerik.Charting.LabelItem 
        Dim i As Integer 
        Dim count As Integer = 0 
        For i = collection.Count - 1 To 0 Step -1 
            temp(count) = collection(i) 
            count += 1 
        Next 
        collection.Clear() 
        collection.AddRange(temp) 
    End Sub 

0
Marc Fearby
Top achievements
Rank 1
answered on 24 Aug 2012, 04:36 AM
Thanks for providing the solution, Travis. This "expected behaviour" excuse just seems like a cover-up for sloppy design. Who in their right mind would want a legend ordered opposite to the many items in a stacked bar chart?
Tags
Chart (Obsolete)
Asked by
Travis
Top achievements
Rank 1
Answers by
Ves
Telerik team
Travis
Top achievements
Rank 1
Marc Fearby
Top achievements
Rank 1
Share this question
or