【问题标题】:parallel coordinates : setup color depending on value of dimension平行坐标:根据尺寸值设置颜色
【发布时间】:2016-08-25 12:09:06
【问题描述】:

我正在尝试根据维度的值更改笔触颜色: 状态 0 = 红色,状态 1 = 格力,状态 3 = 橙色

我尝试使用平行坐标库:https://syntagmatic.github.io/parallel-coordinates/

那里有一个例子,但它很复杂,我无法让它工作,有人可以告诉我如何将它应用到这里的简单例子上吗?

      pcz = d3.parcoords()("#example")
    .data(data)
    .hideAxis([])
    .composite("darken")
    .render()
    .alpha(0.35)
    .brushMode("1D-axes")  // enable brushing
    .interactive()  // command line mode

或者可能是那里的简单示例中的那个?

    <script src="http://d3js.org/d3.v3.min.js"></script>
<script src="d3.parcoords.js"></script>
<link rel="stylesheet" type="text/css" href="d3.parcoords.css">
<div id="example" class="parcoords" style="width:360px;height:150px"></div>

<script>
var data = [
  [0,-0,0,0,0,3 ],
  [1,-1,1,2,1,6 ],
  [2,-2,4,4,0.5,2],
  [3,-3,9,6,0.33,4],
  [4,-4,16,8,0.25,9]
];

var pc = d3.parcoords()("#example")
  .data(data)
  .render()
  .createAxes();
</script>
    enter code here

【问题讨论】:

  • 你能多说一些关于它的外观吗?您想根据值更改每条线穿过不同尺寸时的笔触颜色吗?你有模型吗?

标签: javascript d3.js parallel-coordinates


【解决方案1】:

您需要在初始化时将函数传递给颜色参数,例如:

var color = function(d) {
    if (d['displacement (cc)'] < 100) {
        return 'black';
    } else if (d['displacement (cc)'] > 400) {
        return 'red';
    } else {
        return 'yellow';
    }
};
var parcoords = d3.parcoords()("#example")
    .color(color)
    .alpha(0.4);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-03
    • 1970-01-01
    • 2015-12-28
    • 2021-08-30
    • 2013-04-07
    • 1970-01-01
    相关资源
    最近更新 更多