如何将分类字段传递给三维散点图上的标记颜色(three.js& d3.js)

时间:2017-10-23 14:45:06

标签: javascript d3.js three.js

我想使用分类字段(性别)为此3D散点图上的标记着色:

https://datavizhokie.github.io/conf-hum-int/

我的数据格式:

x,y,z,G
7,5,8,公

最初,颜色是随机分配的,因此每个节点都有独特的颜色。但是,我更新为使用一种颜色,但想要将性别字段传递给颜色:

var pointCount = unfiltered.length;
var pointGeo = new THREE.Geometry();

for (var i = 0; i < pointCount; i ++) {
    var x = xScale(unfiltered[i].x);
    var y = yScale(unfiltered[i].y);
    var z = zScale(unfiltered[i].z);
    pointGeo.vertices.push(new THREE.Vector3(x, y, z));
    console.log(pointGeo.vertices);
    pointGeo.vertices[i].angle = Math.atan2(z, x);
    pointGeo.vertices[i].radius = Math.sqrt(x * x + z * z);
    pointGeo.vertices[i].speed = (z / 100) * (x / 100);
    // **** Assign colors to coordinates
    pointGeo.colors.push(new THREE.Color().setRGB(
      //colour.fromarray(G)
      hexToRgb(colour(2)).r / 255, hexToRgb(colour(10)).g / 255, 
      hexToRgb(colour(5)).b / 255
    )); 
}

从three.js文档中可以看出.fromArray可能是传递性别信息的方式,但我没有成功。这是基于Phil的一个很棒的例子:

http://bl.ocks.org/phil-pedruco/9852362

非常感谢任何读这篇文章的人 - 我对JS有点新鲜。

0 个答案:

没有答案