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

4 posts, 1 answers
  1. Joe
    Joe avatar
    48 posts
    Member since:
    Dec 2007

    Posted 05 Feb 2008 Link to this post

    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
  2. Answer
    Chavdar
    Admin
    Chavdar avatar
    898 posts

    Posted 06 Feb 2008 Link to this post

    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
  3. DevCraft banner
  4. Joe
    Joe avatar
    48 posts
    Member since:
    Dec 2007

    Posted 08 Feb 2008 Link to this post

    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.
  5. Chavdar
    Admin
    Chavdar avatar
    898 posts

    Posted 11 Feb 2008 Link to this post

    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
Back to Top