0

我是第一次使用 D3,我正在尝试制作一个平行坐标图。我基本上正在使用这个演示。我唯一真正的改变是改变数据和改变最右边的轴,所以它有字符串而不是数字作为标签。我通过使用以下内容来做到这一点:

        if(d === "Dog Breed") {
            y[d] = d3.scale.ordinal()
              .domain(dogData.map(function(p) { return p[d]; }))
              .rangePoints([h, 0]);  // quantitative color scale

        }

不幸的是,如果狗的品种太长,文本会被截断,从而难以阅读标签(必须完全移动轴才能阅读,但是当他们放开它时,它会立即回到最初的位置)。

我的其他更改如下:

        var m = [30, 10, 10, 10],
        w = screen.width - 150, // Make it 150px less than the screen's width.
        h = 500 - m[0] - m[2];

轴标签代码在以下位置保持不变:

          // Add an axis and title.
      g.append("svg:g")
          .attr("class", "axis")
          .each(function(d) { d3.select(this).call(axis.scale(y[d])); })
        .append("svg:text")
          .attr("text-anchor", "middle")
          .attr("y", -9)
          .text(String);

有什么办法可以避免名称被剪掉的事情吗?即使将图形本身在其块中移动约 20px 也会有所帮助,但我不知道代码在哪里......

4

1 回答 1

0

解决方法是操纵 var m 在 m[3] 的左侧有更多。

于 2013-10-17T04:46:06.357 回答