【问题标题】:canvasOverlay show in jqplotjqplot中的canvasOverlay显示
【发布时间】:2014-05-18 21:06:55
【问题描述】:

如何仅在单击复选框后(而不是在加载 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 时建议不起作用。

【问题讨论】:

  • 你能给出一些你尝试过的代码吗?您是否尝试将 co.draw(plot1) 替换为 co.replot()?
  • 我刚刚为问题中的 qjplot 添加了 used 函数。
  • 我尝试将 co.draw(plot1) 更改为 plot1.replot() 也没有任何影响

标签: show jqplot overlays


【解决方案1】:

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

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

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

现在,当勾选复选框而不是在开头时,绘图会显示选定的叠加层。 希望这对遇到同样问题的人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多