2016-08-25 26 views
0

我试图根据一个维度的值来改变笔划颜色的值设置颜色: 状态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 
+0

你能说一点关于这将如何看?您是否想要根据值来更改每行的笔触颜色?你有模拟吗? –

回答

0

你需要一个函数传递给颜色参数像初始化:

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);