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

Stacked Chart Legend Order

8 Answers 259 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 12 Jul 2013, 07:34 PM
Hi,

Is there any way to force the items (the data points that are stacked and shown in the legend) in a stacked chart to be in a custom order? Right now it looks like the items are sorted alphabetically but I need them to be in a different order. I couldn't find any way to do this. I also am not sure what term to use to describe the items in the legend for me to do a thorough search.

Thanks,
Chris

8 Answers, 1 is accepted

Sort by
0
Iliana Nikolova
Telerik team
answered on 15 Jul 2013, 12:12 PM
Hello Chris,

By design the legend items' order matches the series' order and presently this behavior cannot be changed. Please excuse us for the inconvenience caused.
 

Regards,
Iliana Nikolova
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 15 Jul 2013, 07:09 PM
Hi Iliana,

Thanks for the response. How do I change the series order? I couldn't figure out how to do that, if it is even possible.

I'm still a little fuzzy about the terminology as well. Especially in the case of stacked charts. I thought the series would be the full bars and this does seems to display in the order that the DataSource reports them in. But the stacked sections appear to be in alphabetical order and the DataSource is NOT reporting them this order. It looks to me like something in the Charting code is sorting these internally.

Thanks,
Chris

0
Iliana Nikolova
Telerik team
answered on 16 Jul 2013, 01:18 PM
Hi Chris,

The series will be ordered depending on their definition order. I.e. the first series in the Chart's configuration will be at the most bottom of the stack.

Regarding the terminology - series are separate parts of the stack, not the full bars (it is the same as in case they are not stacked).  

Regards,
Iliana Nikolova
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 16 Jul 2013, 07:55 PM
Ok, I figured out the issue. I am not creating the series by hand but through grouping in the datasource. When doing this there is no series name. It looks like when there isn't a series name the chart will use the group name. Somewhere in the code when the chart figures out the group names (or maybe this in the datasource?) the names are sorted alphabetically. I am not returning the data like this. In the end I changed my data so it was prepended with a number so it would sort to the order I wanted and then used the groupNameTemplate to get what I wanted. Is there a better way to accomplish what I want without having to build the series array separate from the data? The way I did it seems kind of hack-ish.
0
Iliana Nikolova
Telerik team
answered on 18 Jul 2013, 11:17 AM
Hello Chris,

I am not quite sure if I understand you correctly. Are you using a grouped chart (like in this online demo)? If yes - the series are not sorted by default. Could you please provide a simple runnable example which demonstrates your current implementation and which I can test locally? This way I would be able to advice you further and provide concrete recommendations. Thank you in advance for your time and cooperation.  

Regards,
Iliana Nikolova
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Kelvin
Top achievements
Rank 1
answered on 22 Aug 2013, 05:14 PM
No, what he is saying is that the way the data is displayed was not the way he was sending it back across the wire when the datasource queried his service. I am having the same issue with a simple column chart where it wants to order the displayed series alphabetically.

When I try to accomplish this using the sort methods on the datasource it sorts the individual data elements, not the grouped series.

I want to order of the displayed series (which are groups). Is there a way to accomplish this?

Thanks,

Kelvin
0
Kelvin
Top achievements
Rank 1
answered on 22 Aug 2013, 05:28 PM
Nevermind, figured it out.

Instead of this...
@(Html.Kendo().Chart<T>()
    [... other code ...]
    .DataSource(ds => ds
        .Read(read => read.Action("action", "controller"))
        .Group(g => g.Add(model=> model.property))
    )
    [... other code ...]
)
... do this:
@(Html.Kendo().Chart<T>()
    [... other code ...]
    .DataSource(ds => ds
        .Read(read => read.Action("action", "controller"))
        .Group(g => g.AddDescending(model=> model.property)) // <-- subtle difference here!
    )
    [... other code ...]
)
0
Alex Hajigeorgieva
Telerik team
answered on 07 Feb 2020, 07:45 AM

Hi,

You can use the  legend.reverse  property to change the order of the legend:

https://dojo.telerik.com/@bubblemaster/IpayaKOw/2

Regards,
Alex Hajigeorgieva
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Charts
Asked by
Chris
Top achievements
Rank 1
Answers by
Iliana Nikolova
Telerik team
Chris
Top achievements
Rank 1
Kelvin
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or