1

I have got a question:

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

legend: {
         show: true,
         placement: 'outsideGrid'
},
Nandu
  • 2,990
  • 7
  • 31
  • 51
Butters
  • 877
  • 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,468
  • 2
  • 49
  • 70