简体   繁体   English

jQuery Raphael饼图

[英]JQuery Raphael Pie Chart

I've created a pie chart: 我创建了一个饼图:

http://jsfiddle.net/amakkawy/cLRYq/ http://jsfiddle.net/amakkawy/cLRYq/

r.customAttributes.segment = function(x, y, r, a1, a2) {
    var flag = (a2 - a1) > 180,
    clr = (a2 - a1) / 360;
    a1 = (a1 % 360) * Math.PI / 180;
    a2 = (a2 % 360) * Math.PI / 180;
    return {
        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"]],
        fill: "url(http://www.trendir.com/outdoors/landscape-forms-shade-35-umbrella-under.jpg)"
    };
};

and unsure how to set this code up to have a different image/fill for each segment. 并且不确定如何设置此代码以使每个段具有不同的图像/填充。

Please advise. 请指教。

Thanks 谢谢

you can try out with my code 你可以尝试我的代码

 r.customAttributes.segment = function (x, y, r, a1, a2) {
            var flag = (a2 - a1) > 180,
                    clr = (a2 - a1) / 360;
            a1 = (a1 % 360) * Math.PI / 180;
            a2 = (a2 % 360) * Math.PI / 180;
            return {
                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"]
                ],
                fill: "hsb(" + clr + ", .75, .8)"
            };
        };

http://jsfiddle.net/jophine/E8EU8/ http://jsfiddle.net/jophine/E8EU8/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM