3d生成的SVG没有响应
d3-generated SVG is not responsive
我正在尝试创建一个响应式SVG。我已经成功地创建了一个示例SVG:
<html xmlns:xlink="http://www.w3.org/1999/xlink"><head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
<div id="container">
<svg viewBox="0 0 600 200" preserveAspectRatio="xMidYMid" id="chart">
<circle fill="red" cy="100" cx="100" r="100"></circle>
<circle fill="blue" cy="100" cx="300" r="100"></circle>
<circle fill="green" cy="100" cx="500" r="100"></circle>
</svg>
</div>
</body></html>
https://jsfiddle.net/andrewsu/kombdqL2/4/https://gist.github.com/andrewsu/d3ed340495a2f21a25f8f69dedb2096a 如果您在jsfiddle版本中调整面板边界,您可以看到圆圈的大小适当缩放。
我想使用D3创建完全相同的SVG。
<html xmlns:xlink="http://www.w3.org/1999/xlink"><head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
</head>
<body>
<div id="container">
</div>
<script type="text/javascript">
var width=600, height=200;
var svg = d3.select("#container").append("svg")
.attr("id","chart")
.attr("preserveAspectRatio", "xMidYMid")
.attr("viewbox", "0 0 "+ width + " " + height);
svg.append("circle")
.attr("r","100")
.attr("cx","100")
.attr("cy","100")
.attr("fill","red");
svg.append("circle")
.attr("r","100")
.attr("cx","300")
.attr("cy","100")
.attr("fill","blue");
svg.append("circle")
.attr("r","100")
.attr("cx","500")
.attr("cy","100")
.attr("fill","green");
</script>
</body></html>
https://jsfiddle.net/andrewsu/g1x3s2ny/5/https://gist.github.com/andrewsu/bf0e7549934f93ac40a416dc17bb7b1e 据我所知,呈现的HTML是完全相同的,但是第二个示例不能正确工作(参见jsfiddle)。对我来说奇怪的是,如果我使用浏览器的检查器来改变viewBox属性中的四个数字中的任何一个,行为会立即按预期工作。
想法吗?
viewBox
有一个大写的B:
.attr("viewBox", "0 0 "+ width + " " + height);
现在检查你的小提琴:https://jsfiddle.net/on17ga9u/
文档如下:https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
相关文章:
- D3在一个调用中绘制不同的SVG形状,没有可见性
- 如何使用javascript从主svg对象动态创建svg视图框
- 如何更改<svg>标记为<img>用js标记
- 如何将getJson的响应保存在全局变量中
- 如何使用Spring MVC将Facebook返回的响应数据保存在Java类中
- 使用angularjs向浏览器发送servlet响应(下载功能)
- 锚点元素不't使用svg时,请打开EDGE上的href
- MockJax没有在JavaScript应用程序中发送对我AJAX请求的响应
- 在 xmlhttprequest 响应中使用 svg web
- 使 SVG 映像响应引导容器
- 如何设置响应式 SVG 宽度
- 如何使用Snap.SVG为单个SVG元素做出唯一响应
- 我如何使svg响应
- 响应SVG线形图与Raphaë 1
- CSS和D3 -在FIREFOX中制作响应svg
- D3引导,响应定心svg
- 3d生成的SVG没有响应
- 修改动态生成的SVG,使其响应
- 如何使用d3.js创建响应svg
- 带填充的SVG弧对悬停没有响应