点击按钮打开一个新窗口,用D3画一个大圆
On button click open a new window and draw a large circle with D3
这个问题以前在这里已经回答过了:点击按钮打开一个新窗口,用D3 画一个圆圈
但在meetamit给出的解决方案中:
http://jsfiddle.net/aj3g5tqg/3/
createNewPage();
function drawChart(newWindowRoot){
var sampleSVG = newWindowRoot;
sampleSVG
.append("button")
.text("hi")
.attr("width", 100)
.attr("height", 100);
sampleSVG.append('svg').append("circle")
.style("stroke", "gray")
.style("fill", "red")
.attr("r", 200)
.attr("cx", 100)
.attr("cy", 100)
.on("mouseover", function(){d3.select(this).style("fill", "aliceblue");})
.on("mouseout", function(){d3.select(this).style("fill", "white");});
}
function createNewPage(){
var button = d3.select("body").append("button")
.attr("class", "button")
.attr("id", "myButton")
.text("Visualize");
document.getElementById("myButton").onclick = function () {
var newWindow = window.open('');
newWindowRoot = d3.select(newWindow.document.body)
.attr("width","1060px")
.attr("margin","50px auto");
drawChart(newWindowRoot);
}
}
我无法扩展网格大小来绘制一个大圆圈,比如半径为200的圆圈。我尝试更改"d3.select(newWindow.docent.body)"的宽度属性,但没有效果
如何做到这一点?提前感谢!
附加到新窗口中的svg
元素没有大小:
sampleSVG.append('svg')
.attr('width', 500)
.attr('height', 500) //<-- give the SVG some size
.append("circle")
.style("stroke", "gray")
.style("fill", "red")
.attr("r", 200)
.attr("cx", 250)
.attr("cy", 250)
...
更新的小提琴。
相关文章:
- D3在一个调用中绘制不同的SVG形状,没有可见性
- 使用D3.js和GeoJson在地图上的某些坐标上设置一个小图像
- d3.csv有很多数据,只画了一个月
- D3.js:将一个有响应的饼图放在其父分区的中心
- 在多行图表中,在每一行的末尾,我想要一个小圆圈和使用d3.js的端点值
- D3.js如何只创建一个绑定到多个数据项的数据集的元素
- 如何使用d3.layout.cloud.js创建一个包含单词及其权重的csv的单词云
- 为什么我会得到一个“;未捕获类型错误”;当我介绍D3.transition()时
- 如何用D3添加一个简单的圆弧
- 当鼠标也在触摸另一个元素时,d3.js鼠标悬停事件未被触发
- d3日历视图:如何将所有内容放在一个svg中,而不是放在几个svg中
- 如何使用 d3 过渡使圆形一个接一个地出现
- 在 D3 中追加堆积条形图和另一个条形图
- 如何在D3中添加一个强制拖动事件,并使节点停留在我离开它的地方
- 根据已经给定的频率创建一个d3.js直方图
- D3-使用一个SVG点击事件来影响另一个
- 是什么导致一个D3.js图表和同一页上的另一个发生冲突
- 我可以把一个d3布局放在另一个上面吗
- 如何计算一个D3对角线路径的中心
- D3工具提示,也是一个D3 viz