只需更新傑夫答案:
對於彩色:
通行證顏色參照功能:r.customAttributes.segment = function (x, y, r, a1, a2, color) {...
添加顏色陣列VAR數據後:var data = [90, 90, 90, 90], color = ['#ff0000', '#00ff00', '#0000ff', '#ff0000'], ...
在最後的循環:
start = 0;
for (i = 0; i < ii; i++) {
var val = 360/total * data[i];
var col = color[i]; //Add color from array
(function (i, val) {
//Here we pass the color (col)
paths.push(r.path().attr({segment: [200, 200, 1, start, start + val, col], stroke: "#fff"}).click(function() {
...
編輯:
一個然後(感謝Matt Ball爲一部分)
更改r.customAttributes.segment =函數(X,Y,R,A1,A2,顏色){...與這樣的:
var flag = (a2 - a1) > 180;
a1 = (a1 % 360) * Math.PI/180;
a2 = (a2 % 360) * Math.PI/180;
var props = {
path: [["M", x, y], ["l", r * Math.cos(a1), r * Math.sin(a1)], ["A", r, r, 0, +flag, 1, x + r * Math.cos(a2), y + r * Math.sin(a2)], ["z"]]
};
if (color) {
props.fill = color;
}
return props;