2013-11-25 68 views
1

我是新來D3,我嘗試使用http://syntagmatic.github.io/parallel-coordinates/如何使用尺寸與D3 parcoords

在這裏,您從網站上看到簡約的例子。

<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() 
    .ticks(3) 
    .createAxes(); 
</script> 

我想要一些尺寸不顯示,並嘗試#parcoords.dimensions(尺寸)的不同方法。你會如何解決這個問題?

回答

2

我看了一下小提琴格拉特的設置,但看起來並沒有像我認爲的那樣工作。在該小提琴中,尺寸的名稱已被刪除,但尺寸之間的鏈接或線條仍然代表原始數據。這種行爲對我來說似乎很奇怪,可能是一個錯誤。

無論如何,我已經設置了一個小提琴,使用預過濾器中的數據:

data.forEach(function (e,j) { 
    var temp ={}; 
    filteredDimensions.forEach (function (d,i) { 
     temp[d] = e[d] 
    }) 
    filteredData.push(temp) 
}) 

與工作小提琴here

+0

這些名字沒有被刪除,OP從未提供過。 – Gerrat

1

只需添加您的.dimensions()通話.ticks()後,和前.createAxes()

var pc = d3.parcoords()("#example") 
    .data(data) 
    .render() 
    .ticks(3) 
    .dimensions([1,2,4]) 
    .render() 
    .createAxes(); 

的jsfiddle here

看着user1614080的解決方案後,他只是對數據進行過濾名列前茅的時間,這是很容易,並始終可用,但不是你要求的。我嘗試使用他的例子(與名稱),並使用維的名稱(jsFiddle here)。我做到這一點的方式對命名維度也很有效。

尺寸只需要在.render()之後的某處,但我不知道爲什麼。

編輯:終於明白了爲什麼這個顯示不正確。需要在更新尺寸後調用.render()(稍微提及here)。兩個示例都已更新,以修復軸之間的拐點。

+0

也感謝您的回答。我總是想知道如何訂購方法。你偶然知道一個教程,或者你有很好的解釋嗎? – gimba

+0

不...我只是試圖讓它工作,並認爲我有。也許不會。 – Gerrat

+0

經仔細檢查,我是對的。這是您過濾尺寸的方式(我添加了第二個jsfiddle) – Gerrat