Manage jqplot legend for each series. ShowLabel series does not work with EnhancedLegendRenderer

I want to selectively hide the legends of some episodes in the plot. And this http://www.jqplot.com/docs/files/jqplot-core-js.html#Series.showLabel looks like the right option for this.

But using series:{showLabel:false}with does not work.

Open (old) ticket in this regard: https://bitbucket.org/cleonello/jqplot/issue/100/feature-request-individual-legend-control

Am I using this correctly? Any other workarounds to achieve this are also welcome.

Update:

showLabel works great with regular legendRenderer.

+5
source share
3 answers

draw jqplot.enhancedLegendRenderer.js 132:

if (idx < series.length && (series[idx].show || series[idx].showLabel)){

, . , ( - true), . , , showLabel false, .

|| && - . .

Edit:

, , , .

tr , showLabel - false. if :

tr = $(document.createElement('tr'));
tr.addClass('jqplot-table-legend');
if (reverse){
    tr.prependTo(this._elem);
}
else{
    tr.appendTo(this._elem);
}

(, , if, ):

if (idx < series.length && (series[idx].show && series[idx].showLabel)){
    tr = $(document.createElement('tr'));
    tr.addClass('jqplot-table-legend');
    if (reverse){
        tr.prependTo(this._elem);
    }
    else{
        tr.appendTo(this._elem);
    }
}

( 212), :

if (this.showLabels)  {
    console.log(this._elem.find('tr').length - 1);
    td2.bind('click', {series:s, speed:speed, plot: plot, replot:this.seriesToggleReplot }, handleToggle);
    td2.addClass('jqplot-seriesToggle');
}

, . , , click:

td2.bind('click', {series:s, speed:speed, plot: plot,
    replot:this.seriesToggleReplot,
    trIndex: this._elem.find('tr').length - 1 }, handleToggle);

trIndex HTML. , .

doLegendToggle :

if (s.canvas._elem.is(':hidden') || !s.show) {
    // Not sure if there is a better way to check for showSwatches and showLabels === true.
    // Test for "undefined" since default values for both showSwatches and showLables is true.
    if (typeof plot.options.legend.showSwatches === 'undefined' || plot.options.legend.showSwatches === true) {
        plot.legend._elem.find('td').eq(sidx * 2).addClass('jqplot-series-hidden');
    }
    if (typeof plot.options.legend.showLabels === 'undefined' || plot.options.legend.showLabels === true) {
        plot.legend._elem.find('td').eq((sidx * 2) + 1).addClass('jqplot-series-hidden');
    }
}
else {
    if (typeof plot.options.legend.showSwatches === 'undefined' || plot.options.legend.showSwatches === true) {
        plot.legend._elem.find('td').eq(sidx * 2).removeClass('jqplot-series-hidden');
    }
    if (typeof plot.options.legend.showLabels === 'undefined' || plot.options.legend.showLabels === true) {
        plot.legend._elem.find('td').eq((sidx * 2) + 1).removeClass('jqplot-series-hidden');
    }
}

. sidx, , trIndex. sidx d.trIndex.

+1

jqplot:

$($("#chartXXX .jqplot-table-legend").get(0)).hide();

get(), , . , LegendRenderer.

+2

Ok, I combined the answer from jbass and from DaFrenk, and the result:

$($("#chartXXX tr.jqplot-table-legend").get(0)).hide();

Number in getis a zero-based index that defines a row in the legend table. This does exactly what I want.

0
source

All Articles