1

我正在尝试使用平行坐标库来绘制一些数据。我拥有的数据点的坐标都是字符串。例如考虑下CSV表:

ID,TYPE,USER,OS,FooBar,Country
a1,X,1S,iOS,foo,US
a2,Y,1S,Android,bar,US

这是两个数据点,每个数据点有六个属性。我拥有的htmlMWE 如下:

<!doctype html>

<link rel="stylesheet" type="text/css" href="d3.parcoords.css">
<script src="./d3.min.js"></script>
<script src="./d3.parcoords.js"></script>
<script src="./divgrid.js"></script>


<style>
/* data table styles */
#grid { height: 198px; }
.row, .header { clear: left; font-size: 12px; line-height: 18px; height: 18px; }
.row:nth-child(odd) { background: rgba(0,0,0,0.05); }
.header { font-weight: bold; }
.cell { float: left; overflow: hidden; white-space: nowrap; width: 100px; height: 18px; }
.col-0 { width: 180px; }
.col-1 { width: 80px; }
.col-2 { width: 180px; }
.col-3 { width: 150px;}
</style>

<title>Minimal Working Example</title>

<body>
<div id="visual" class="parcoords" style="width:1280px;height:350px"></div>
<p>Lines from the data</p>
<div id="grid"></div>
</body>


<!-- Setting and inserting the visualization and the corresponding table -->
<script>
 var parcoords = d3.parcoords()("#visual").color("steelblue");

 /*
 Load the data and visualize it
  */
 d3.csv('first-100.csv',function(data) {
   parcoords.data(data)
        .tickFormat(function(d) {return'';})
        .render().brushable().reorderable();

   var grid = d3.divgrid();
   d3.select("#grid")
     .datum(data.slice(0,30))
     .call(grid)
     .selectAll(".row")
     .on({
     "mouseover": function(d) { parcoords.highlight([d]) },
     "mouseout": parcoords.unhighlight
     });

   // update data table on brush event
   parcoords.on("brush", function(d) {
     d3.select("#grid")
       .datum(d.slice(0,30))
       .call(grid)
       .selectAll(".row")
       .on({
       "mouseover": function(d) { parcoords.highlight([d]) },
       "mouseout": parcoords.unhighlight
     });
   });
 });
</script>

不幸的是,正如您在屏幕截图中看到的那样,这只绘制了四 (4) 个坐标...我认为问题与所有坐标都是字符串这一事实有关,但我不确定。

在此处输入图像描述

任何建议如何纠正这个问题?

4

1 回答 1

2

问题是平行坐标库会过滤掉数据集中唯一值少于两个的维度,数据中的“用户”和“国家”列就是这种情况。

相关的源代码在这里。当前版本的 d3.parcoords.js 中的第 168 行,它起源于目录中的autoscale.js文件src。这是链接断开时的代码:

// hack to remove ordinal dimensions with many values
pc.dimensions(pc.dimensions().filter(function(p,i) {
  var uniques = yscale[p].domain().length;
  if (__.types[p] == "string" && (uniques > 60 || uniques < 2)) {
    return false;
  }
  return true;
}));

在您的情况下,如果您想强制呈现有问题的两列,一种解决方案是简单地在 d3.parcoords.js 文件中注释掉这个块。

这是您的示例的一个PLUNK,我在其中注释掉了上面的代码块。现在输出如您所愿。希望有帮助。

于 2014-07-21T16:04:58.647 回答