0

我很抱歉,因为我知道这是一个重复的问题,但我已经尽我所能搜索并尝试了我发现的所有内容,但似乎没有任何效果。我想做的是在我的html文档中动态分配一个div,然后用google可视化图表填充它。

除了一件事,我所有这些都正常工作。我不能让 div 的该死的尺寸增加!这是我的代码:

var thisDashboard = document.createElement(chartDivID);
thisDashboard.setAttribute("style", "width: 1000 px; height 425 px;");
thisDashboard.setAttribute("id", chartDivID);
//thisDashboard.style.height = 425 + "px";
//thisDashboard.style.width = "1000px";
document.getElementById("chartArea").appendChild(thisDashboard);

var thisChart = document.createElement(chartDivID + "_chart");
thisChart.setAttribute("style", "height: 300 px; width: 100%");
thisChart.setAttribute("id", chartDivID + "_chart");
//thisChart.style.height = 300 + "px";
//thisChart.style.width = 100 + "%";
thisDashboard.appendChild(thisChart);

如您所见,我已经尝试了使用 .setAttribute 与 .style.width 和 .style.height 之间能想到的所有组合。出于某种原因,它只是行不通。这是图表区域 div:

<div id="chartArea" style="width: 100%"></div>

我能够使隐藏的元素出现在新创建的 div 中,但宽度不会改变!我在这里错过了一些非常明显的东西吗?

4

1 回答 1

0

width: 100% should work, but it means that div takes all the place in width it can, so if it's for example in the table column, which's width is smaller, the div wouldn't expand it, just fit in it :)

于 2013-07-08T13:37:24.650 回答