javascript - 您可以使用 D3.js 将数据绑定到 A-Frame 基元吗?
问题描述
我正在尝试<a-box>
根据使用 D3.js 的数据值更改 12 A 框架的高度。制作 3D 条形图。
使用下面的代码,A 框架可以正常工作,但高度、宽度和深度不受 d3 的影响。
<a-scene>
<!-- Bar chart-->
<a-entity>
<a-box position=".5 -1 .5" color="#000000"></a-box>
<a-box position="1.5 -1 .5" color="#FFFFFF"></a-box>
<a-box position="2.5 -1 .5" color="#000000"></a-box>
<a-box position=".5 -1 1.5" color="#FFFFFF"></a-box>
<a-box position="1.5 -1 1.5" color="#000000"></a-box>
<a-box position="2.5 -1 1.5" color="#FFFFFF"></a-box>
<a-box position=".5 -1 2.5" color="#000000"></a-box>
<a-box position="1.5 -1 2.5" color="#FFFFFF"></a-box>
<a-box position="2.5 -1 2.5" color="#000000"></a-box>
<a-box position=".5 -1 3.5" color="#FFFFFF"></a-box>
<a-box position="1.5 -1 3.5" color="#000000"></a-box>
<a-box position="2.5 -1 3.5" color="#FFFFFF"></a-box>
</a-entity>
<a-light color="#da47da" position="0 0 0" type="ambient"></a-light>
<a-entity light="type: point; color: #EEE; intensity: 0.5" position="0 3 0"></a-entity>
<a-entity position="0 0 0" rotation="0 0 0">
<a-entity camera look-controls wasd-controls></a-entity>
</a-entity>
<!-- Sky -->
<a-sky color="#c8f7f0"></a-sky>
</a-scene>
<script>
// fake sample data
var data = [10, 20, 30, 15, 25, 35, 40,
45, 50, 70, 100, 120]
var yscale = d3.scaleLinear()
.domain([0, d3.max(data)])
.range([0, 3])
var scene = d3.select("a-scene")
var bars = scene.selectAll("a-box")
.data(data)
.attr({
position: (d, i) => {
y = yscale(d) / 2;
return x + "" + y + "" + z + "";
},
height: d => d,
width: d => 0.9,
depth: d => 0.9,
})
</script>
解决方案
bars.enter().append("a-entity")
bars.attr("height", function (d) { return yscale(d) });
bars.attr("width", function (d) { return 0.9 });
bars.attr("depth", function (d) { return 0.9 });
我使用了错误的语法。d3 v5 显然不允许多个属性。
推荐阅读
- regex - RegEx 表示字符串开头没有空格
- python - 如何对通过 VPN 连接的远程服务器执行 udp 连接?
- python - 是否可以使用列表来存储列表框数据,Tkinter
- javascript - 如何在不基于参数获取的情况下将 JSON 发送到前端?
- java - Nimbus 反应式 JWT 解码器“NimbusReactiveJwtDecoder.withJwkSetUri()”无法解析负载平衡 url lb:// 的主机
- react-native - React-native-sound 创建无限循环
- linux - Linux在句子中显示2个单词之间的字符串
- node.js - MongoDB DISTINCT/UNIQUE 值计数而不使用 countDocuments() 或 distinct() [猫鼬,节点]
- c# - 通过 C# 将 Unicode 从 JSON 绑定到 XAML 不起作用。有办法吗?
- django - 通过外键过滤 Tastypie 资源