在弹出窗口中显示nvd3 pieChart时出现问题? [英] Problems while displaying nvd3 pieChart in a pop up window?

查看:111
本文介绍了在弹出窗口中显示nvd3 pieChart时出现问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在弹出窗口中打开nvd3 pieChart.我这样创建弹出窗口:

I am opening nvd3 pieChart in a popup window. I create popup window like this:

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));
}

然后我使用以下代码创建一个pieChart:

then I create a pieChart using following code:

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);

我在单击按钮时执行了上面的代码,这会在弹出窗口中打开一个图表,但有时它无法正确显示,看起来像这样:

I execute the above code on button click which opens a chart in pop up but sometimes it doesn't appear correctly and looks like this:

当我切换标签并再次关注弹出窗口时,它正确显示为:

When I switch tabs and focus on pop window again it appears correctly as:

但是,所有图表属性仍然无法正常工作,例如"growOnHover",但是当我在普通的html页面而不是弹出窗口中显示图表时,相同的代码也可以正常工作,我想这与弹出窗口有关, NVD3是问题吗?谁能指出这个问题?

However, all chart properties still doesn't work fine, for example "growOnHover" but the same code works fine when I display chart in a normal html page instead of popup, I guess it has something to do with popup window, Is it the problem with NVD3,? Can anyone point out the issue ?

推荐答案

尝试一下:

nv.utils.windowResize(chart.update);

这将在调整窗口大小时更新图表.弹出窗口可能会发生这种情况.

This will update the chart when the window is resized. Which may happen in the case of popup window.

我不确定您如何打开弹出窗口.您可以使用

I am not sure how you open the popup window. You could use

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

这篇关于在弹出窗口中显示nvd3 pieChart时出现问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆