1

如何仅在单击复选框后(而不是在加载 html 时)触发 jqplot 中的叠加层。当我第一次将叠加选项显示设置为 false 时,叠加不会显示在第 1 次绘图上,而当我使用触发功能时,叠加不会出现。这是我用于绘图的代码:

<div id="fastest" style="margin-top:20px; margin-left:20px; margin-right:200px; width:800px; height:400px;">
<script class="code" type="text/javascript">
$(document).ready(function(){
var dataset="too long to be displayed here"
plot1 = $.jqplot('fastest', dataset, { 
    title: 'Test_figs',
    legend: {show:false},
    series: [{
        showMarker: false, 
        color: '#ED0E0E',
        label: 'R spectrum', 
        neighborThreshold: -1
    }],
    axes:{ 
        xaxis:{
            label:'Restframe Wavelength'
        },
        yaxis:{
            label:'Flux', 
            tickOptions:{formatString:'%.3e'}
        }
    },
    cursor:{ 
        show:true,
        zoom:true, 
        tooltipLocation:'sw'
    },

    Canvasoverlay: {
        show: false, 
        objects: [

            {verticalLine: {
                name: 'Na-ID', 
                x: 5893.000000, 
                lineWidth: 2, 
                color: '#F0630C', 
                lineCap:'butt', 
                yOffset:0, 
                shadow: true
            }}
        ]
    }
});
});

function NaID_trigger() {
var co = plot1.plugins.canvasOverlay;
var line = co.get('Na-ID');
if (line.options.show==false) line.options.show = true;
else line.options.show = false;
co.draw(plot1);
}
</script>

然后我使用:

<button onclick="NaID_trigger()">Na-ID</button>

例如触发覆盖打开或关闭。

PS:我尝试用 replot 替换 draw,因为当覆盖选项中的 show=false 时建议不起作用。

4

1 回答 1

0

我终于自己找到了解决方案:为了在 jqplot 加载时不显示叠加层,我将整体叠加层“显示”选项设置为 true。然后在我将 show 设置为 false 的每个对象中。

而不是我在切换到表单的偶数处理程序之前使用的绘图函数的外部:

$("input[type=checkbox][name=Na-ID]").change(function(){
    plot1.plugins.canvasOverlay.get('Na-ID').options.show = this.checked;
    plot1.replot();
});

现在,当复选框被打勾时而不是在开始时,绘图显示所选覆盖层。希望这会帮助有同样问题的人。

于 2014-05-21T15:56:31.800 回答