2016-08-08 50 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