gpt4 book ai didi

javascript - 具有使 d3 图表响应的像素值的 View 框无法正常工作

转载 作者:行者123 更新时间:2023-11-28 01:20:22 25 4
gpt4 key购买 nike

我正在尝试让 d3 图表更具响应性。所以我使用了带有像素值的 viewbox 但它不起作用检查这个 non responsive jsfiddle 。如果我将 widthheight 设置为 100% 如下所示,那么它是响应式检查 responsive jsfiddle

var svg = d3.select('.chart-container').append("svg")
.attr("width", '100%')
.attr("height", '100%')
.attr('viewBox','0 0 '+Math.min(width,height) +' '+Math.min(width,height) )

这不起作用,如非响应式 jsfiddle

中所示
var svg = d3.select('.chart-container').append("svg")
.attr("width", 200)
.attr("height", 200)
.attr('viewBox','0 0 '+Math.min(width,height) +' '+Math.min(width,height) )

我只想在 d3 中自定义 widthheight,而不是通过设置 heightwidth 在 css 中div 并且我不想使用任何 jquery 函数。

最佳答案

如果你去掉高度和宽度属性,那么它就会变得响应式

 var svg = d3.select('.chart-container').append("svg")
.attr('viewBox','0 0 '+Math.min(width,height) +' '+Math.min(width,height) )
.attr('preserveAspectRatio','xMinYMin')
.append("g")
.attr("transform", "translate(" + Math.min(width,height) / 2 + "," + Math.min(width,height) / 2 + ")");

关于javascript - 具有使 d3 图表响应的像素值的 View 框无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23341042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com