docs: function getLegendEntries(series, labelFormatter, sorted) {
          var lf = labelFormatter,
              legendEntries = series.map(function(s, i) {
                  return {
                      label: (lf ? lf(s.label, s) : s.label) || 'Plot ' + (i + 1),
                      color: s.color,
                      options: {
                          lines: s.lines,
                          points: s.points,
                          bars: s.bars
                      }
                  };
              });
  
          // Sort the legend using either the default or a custom comparator
          if (sorted) {
              if ($.isFunction(sorted)) {
                  legendEntries.sort(sorted);
              } else if (sorted === 'reverse') {
                  legendEntries.reverse();
              } else {
                  var ascending = (sorted !== 'descending');
                  legendEntries.sort(function(a, b) {
                      return a.label === b.label
                          ? 0
                          : ((a.label < b.label) !== ascending ? 1 : -1 // Logical XOR
                          );
                  });
              }
          }
  
          return legendEntries;
      }