我期待創建多個進度圈。 (所以,從一個數據集中畫出3個圓)創建多個進度圈d3.js
我一直在嘗試適應this的例子,但正如你所看到的,我已經在某個地方嚴重錯了。
我採取的第一步是將所有數據更改爲數據,因爲我會希望選項動態處理數據。然後,我試圖簡化代碼,以便我更容易理解。 (我是一個D3新手!)
現在,我不知道發生了什麼,希望有人能幫助我達到最終結果?
這是一個fiddle和我的代碼;
/*global d3*/
var width = 240,
height = 125,
min = Math.min(width, height),
oRadius = min/2 * 0.8,
iRadius = min/2 * 0.85,
color = d3.scale.category20();
var arc = d3.svg.arc()
.outerRadius(oRadius)
.innerRadius(iRadius);
var pie = d3.layout.pie().value(function(d) {
return d;
}).sort(null);
var data = [
[20],
[40],
[60]
];
// draw and append the container
var svg = d3.select("#chart").selectAll("svg")
.data(data)
.enter().append("svg")
.attr("width", width).attr("height", height);
svg.append('g')
.attr('transform', 'translate(75,62.5)')
.append('text').attr('text-anchor', 'middle').text("asdasdasdas")
// enter data and draw pie chart
var path = svg.selectAll("path")
.data(pie)
.enter().append("path")
.attr("class", "piechart")
.attr("fill", function(d, i) {
return color(i);
})
.attr("d", arc)
.each(function(d) {
this._current = d;
})
function render() {
// add transition to new path
svg.selectAll("path")
.data(pie)
.transition()
.duration(1000)
.attrTween("d", arcTween)
// add any new paths
svg.selectAll("path")
.data(pie)
.enter().append("path")
.attr("class", "piechart")
.attr("fill", function(d, i) {
return color(i);
})
.attr("d", arc)
.each(function(d) {
this._current = d;
})
// remove data not being used
svg.selectAll("path")
.data(pie).exit().remove();
}
render();
function arcTween(a) {
var i = d3.interpolate(this._current, a);
this._current = i(0);
return function(t) {
return arc(i(t));
};
}
謝謝大家!
它,因爲你的數據是3個數組的數組,所以它會吸取它的3倍 – thatOneGuy
是的,對不起,如果我的職位是誤導?這是我想達到的目標。 – lolio