我正在使用以下代码来设置响应式的SVG
outerHeight = 400;
outerWidth = 600;
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = outerWidth - margin.left - margin.right,
height = outerHeight - margin.top - margin.bottom;
var svg = d3.select("div#simulation-1")
.append("svg")
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("viewBox", "0 0 "+outerWidth+" "+outerHeight)
.attr("class","svg");
这在Chrome中能够完美地工作。然而,在IE11和Firefox中,整个图表都被缩小了(轴和字体都很小),而viewBox的值为
viewbox="0 0 1936 1056"
由于某些原因,它不接受指定的高度和宽度。但是它仍然是响应式的。
包含示例:https://jsfiddle.net/4p73n364/
有任何想法吗? 问候, Jean