1

I have got a question:

Is it possible to sort labels of my legend at Jqplot?

legend: {
         show: true,
         placement: 'outsideGrid'
},
Nandu
  • 3,076
  • 8
  • 34
  • 51
Butters
  • 977
  • 5
  • 14
  • 25

1 Answers1

2

You could use something like this to sort the rows in the legend (inspired by How may I sort a list alphabetically using jQuery?):

var rows = $('#chart .jqplot-table-legend tr').get();
rows.sort(function(a, b) {
    return $(a).children().last().text().localeCompare($(b).children().last().text());
});

$.each(rows, function(index, item) {
    $('#chart .jqplot-table-legend tbody').append(item);
});

This works best for the standard legend renderer - it will also work for the EnhancedLegendRenderer, but toggling a series visible/invisible will actually show or hide the series that corresponded to the label that was there prior to being sorted.

Community
  • 1
  • 1
nick_w
  • 14,758
  • 3
  • 51
  • 71