d3.select.style不适用于firefox

d3.select.style not working on firefox

本文关键字:适用于 firefox 不适用 style select d3      更新时间:2023-09-26

我只是花了大量令人尴尬的时间来解决这个错误,并想记录答案。

以下代码在Chrome上有所需的结果,但在Firefox上没有:

svg=d3.select('svg').style({height : 100,width : 200})

为什么?

答案

svg=d3.select('svg').style({height : 100 + "px", width : 200 + "px"})

看起来Chrome决定默认为"px",而Firefox则希望您明确。

希望这能帮助任何有同样问题的人。