2016-08-08 52 views
0

我在彈出窗口中打開nvd3餅圖。我創建彈出窗口是這樣的:在彈出窗口中顯示nvd3 pieChart時的問題?

function openPopup(html,pos,style) { 
    var newWindow = window.open(''); 
    newWindow.document.write(html); 
    return newWindow; 
} 

function openChartPopup(chartID,chartTitle) { 
    divId = "div" + chartID; 
    html = "<p>"+chartTitle+"</p><div id= \""+divId+"\"><svg id=\""+chartID+"\"></svg></div>"; 
    newWindow = openPopup(html,"_blank",""); 
    return d3.select(newWindow.document.getElementById(chartID)); 
} 

然後創建使用餅圖下面的代碼:

de_select = openChartPopup("test_chart","TEst Chart"); 
    var chart = nv.models.pieChart() 
     .x(function(d) { return d.label }) 
     .y(function(d) { return d.value }) 
     .showLabels(true) 
     .growOnHover(true); 
    de_select.datum(exampleData()); 
    de_select.style({"width":"400px", "height":"500px"}); 
    de_select.transition().duration(350); 
    de_select.call(chart); 
    nv.addGraph(chart); 

我執行按鈕點擊上面的代碼中打開一個圖表中彈出,但有時它不」牛逼正確顯示,看起來像這樣: enter image description here

當我切換標籤並注重彈出窗口再次正確顯示爲: enter image description here

然而,所有的圖表屬性仍然無法正常工作,例如「growOnHover」但同樣的代碼工作正常,當我在一個普通的HTML頁面,而不是彈出顯示的圖表,我想它是與彈出式窗口,這是NVD3的問題嗎?任何人都可以指出這個問題嗎?

回答

2

試試這個:

nv.utils.windowResize(chart.update); 

當窗口大小這將更新圖表。在彈出窗口的情況下可能會發生這種情況。

我不知道你是如何打開彈出窗口。你可以使用

newWindow = window.open("",title, "width=400,height=500"); 
newWindow.document.write(html); 
+0

雖然這個代碼片斷可以解決的問題,[包括說明](// meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)確實有助於提高您的帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。也請儘量不要使用解釋性註釋來擠佔代碼,因爲這會降低代碼和解釋的可讀性! – FrankerZ

+0

@FrankerZ感謝您的評論。我更新 – programmer1490

+0

@ programmer1490,我使用相同的代碼,你提到openPopup是一個功能,我已經更新了,你可以看到帖子的答案。此外,我想你的窗口大小調整的建議,但沒有奏效 – TechMaster