Siv*_*iva 5 legend series jqplot
我希望有选择地隐藏一些情节中的一些系列的传说.这个http://www.jqplot.com/docs/files/jqplot-core-js.html#Series.showLabel看起来是正确的选择.
但使用series:{showLabel:false}与似乎不起作用.
这方面的开放(旧)票:https://bitbucket.org/cleonello/jqplot/issue/100/feature-request-individual-legend-control
我用它了吗?任何其他解决方法来实现这一点也是值得赞赏的.
更新:
showLabel 适用于普通的LegendRenderer.
在draw该文件的函数中jqplot.enhancedLegendRenderer.js,我们在第 132 行左右看到了这一点:
if (idx < series.length && (series[idx].show || series[idx].showLabel)){
Run Code Online (Sandbox Code Playgroud)
对于上下文,这段代码是创建图例表的功能的一部分。如果系列设置为显示(默认为true)或要显示系列标签,则会创建一行。这意味着,为了防止为系列创建图例项,您需要隐藏整个系列本身,以及设置showLabel为false,这并不理想。
相反,尝试将||-&&这在我的情况下有效。首先尝试对未缩小的版本进行更改。
编辑:
首先要做的就是进行我在原始答案中建议的更改。
接下来,如果is ,我们需要阻止tr创建图例中的元素。在上面提到的 if 语句之前,您将看到以下代码:showLabelfalse
tr = $(document.createElement('tr'));
tr.addClass('jqplot-table-legend');
if (reverse){
tr.prependTo(this._elem);
}
else{
tr.appendTo(this._elem);
}
Run Code Online (Sandbox Code Playgroud)
将其更改为这样(我们在这里所做的就是将其包装在我们之前使用的相同 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);
}
}
Run Code Online (Sandbox Code Playgroud)
再向下滚动(大约第 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');
}
Run Code Online (Sandbox Code Playgroud)
这是在图例中单击系列之一时绑定的事件处理程序。我们需要做的是向对象字面量添加一个附加属性,该属性封装了传递给该click方法的数据:
td2.bind('click', {series:s, speed:speed, plot: plot,
replot:this.seriesToggleReplot,
trIndex: this._elem.find('tr').length - 1 }, handleToggle);
Run Code Online (Sandbox Code Playgroud)
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');
}
}
Run Code Online (Sandbox Code Playgroud)
查看对sidx变量的这四个引用,更改它们,以便代码使用该trIndex变量。为此,请将四个sidx引用替换为d.trIndex。
| 归档时间: |
|
| 查看次数: |
4650 次 |
| 最近记录: |