ファイル内のdraw
関数では、jqplot.enhancedLegendRenderer.js
132行目あたりでこれを確認できます。
if (idx < series.length && (series[idx].show || series[idx].showLabel)){
コンテキストとして、このコードは凡例テーブルを作成する機能の一部です。シリーズが表示されるように設定されている場合(デフォルトはtrue
)、またはシリーズラベルが表示される場合は、行が作成されます。つまり、シリーズの凡例アイテムが作成されないようにするには、シリーズ全体を非表示にする必要があり、に設定する必要がありますがshowLabel
、false
これは理想的ではありません。
代わりに、をに設定してみ||
てください&&
-これは私の場合はうまくいきました。最初に、縮小されていないバージョンに変更を加えてみてください。
編集:
最初に行うことは、元の回答で提案した変更を加えることです。
次に、が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);
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');
}
}
変数へのこれらの4つの参照を参照しsidx
、コードが代わりにtrIndex
変数を使用するように変更してください。これを行うには、4つのsidx
参照をに置き換えd.trIndex
ます。