2016-12-07 57 views
1

我想做一個徑向時鐘,但不是時鐘武器,我需要在每個指示時間(藍色)的路徑末尾有點。謝謝您的幫助!d3.js徑向時鐘,加點而不是時針

編輯:這樣的:https://puu.sh/sH03Y/c59281fb5e.png

畫線部分:

var clockLine = linesLayer.selectAll('.clock-line') 
.data(fields); 

clockLine.enter().append('line') 
.attr('class', function (d) { return 'line clock-line ' + d.id; }) 
.attr('x1', 0).attr('y1', 0); 

完全小提琴:http://jsfiddle.net/zh3owyr3/

+1

你是什麼意思的「每個路徑末尾的點指示時間(藍色)」?像小時指標? – echonax

+0

喜歡這個例子:https://puu.sh/sH03Y/c59281fb5e.png – Mantom

回答

3

取而代之的是<line>的,追加<circle>

var clockCircle = linesLayer.selectAll('.clock-line') 
    .data(fields); 

clockCircle.enter().append('circle') 
    .attr('class', function(d) { 
     return 'circle clock-circle ' + d.id; 
    }) 
    .attr("r", 6) 
    .attr("fill", "teal"); 

而且CH安格其位置在tick功能:

clockCircle.attr('cx', function(d) { 
    return d.index * radius * Math.cos(d.value * 2 * Math.PI - Math.PI/2); 
}) 
.attr('cy', function(d) { 
    return d.index * radius * Math.sin(d.value * 2 * Math.PI - Math.PI/2); 
}); 

這是你更新的提琴:http://jsfiddle.net/mjru5ta8/

PS:你必須改變你的視框中,以避免被裁剪的秒圈子。