5

プロット内のシリーズの伝説を選択的に非表示にしたいと考えています。そして、このhttp://www.jqplot.com/docs/files/jqplot-core-js.html#Series.showLabelは、これに対する正しいオプションのようです。

しかし、series:{showLabel:false}with を使用してもうまくいかないようです。

この点に関するオープン (古い) チケット: https://bitbucket.org/cleonello/jqplot/issue/100/feature-request-individual-legend-control

私はそれを正しく使用していますか?これを達成するための他の回避策も高く評価されます。

アップデート:

showLabel通常の legendRenderer で問題なく動作します。

4

3 に答える 3

2

jqplot の下に次の行を追加します。

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

数値が凡例要素にどのようにマップされているか正確にはわからないため、get() 内の数値をいじってみてください。このソリューションは、EnhancedLegendRenderer コードを変更するよりもはるかに洗練されています。

于 2013-06-07T16:50:11.260 に答える
1

ファイル内のdraw関数では、jqplot.enhancedLegendRenderer.js132行目あたりでこれを確認できます。

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

コンテキストとして、このコードは凡例テーブルを作成する機能の一部です。シリーズが表示されるように設定されている場合(デフォルトはtrue)、またはシリーズラベルが表示される場合は、行が作成されます。つまり、シリーズの凡例アイテムが作成されないようにするには、シリーズ全体を非表示にする必要があり、に設定する必要がありますがshowLabelfalseこれは理想的ではありません。

代わりに、をに設定してみ||てください&&-これは私の場合はうまくいきました。最初に、縮小されていないバージョンに変更を加えてみてください。

編集:

最初に行うことは、元の回答で提案した変更を加えることです。

次に、が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');
}

これは、凡例でシリーズの1つがクリックされたときのイベントハンドラーをバインドします。私たちがする必要があるのは、clickメソッドに渡されるデータをカプセル化するオブジェクトリテラルに追加のプロパティを追加することです。

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

trIndexHTMLテーブルの行の実際のインデックスを表します。凡例が正しい要素を打ち消すことを保証するのはこれです。

宣言の中には、次の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');
    }
}

変数へのこれらの4つの参照を参照しsidx、コードが代わりにtrIndex変数を使用するように変更してください。これを行うには、4つのsidx参照をに置き換えd.trIndexます。

于 2013-03-06T21:34:17.480 に答える