2014-05-18 42 views
1

只有當我點擊一個複選框(不是在加載html時)時,我如何觸發jqplot中的疊加層。當我第一次設置覆蓋選項顯示爲false時,覆蓋圖不會顯示在第一張圖上,當我使用觸發功能時,覆蓋圖不會出現。 這裏是我使用的情節代碼:canvasOverlay在jqplot中顯示

<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,因爲在覆蓋選項中顯示= false時建議不工作。

+0

你可以給你一些代碼嗎?你有沒有試圖用co.replot()替換co.draw(plot1)? – AnthonyLeGovic

+0

我只是在問題中添加了qjplot的使用函數。 – Demetrius

+0

我嘗試將co.draw(plot1)更改爲plot1.replot()以及沒有任何效果 – Demetrius

回答

0

我終於找到了自己的解決方案: 當jqplot加載時不顯示覆蓋圖我將整體覆蓋「show」選項設置爲true。 然後在我設置的每個對象中顯示爲false。

取而代之的是外部之前,我切換到,甚至處理形式的我用的繪圖功能的:

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

現在,當複選框在開始時被選中,而不是圖上顯示所選擇的覆蓋。 希望這會幫助有同樣問題的人。