【发布时间】:2013-11-19 11:27:00
【问题描述】:
我正在尝试根据变量填充圆的边框,如下所示:
我找到了this example,但这不是我想要的。我希望外边框从下往上填充,在圆的两侧。
这是我的代码:
var completion = '5%';
drawcircle("js-raphael-completion", completion);
function drawcircle(div, rate) {
var archtype = Raphael(document.getElementsByClassName(div)[0], "90%", "90%");
archtype.customAttributes.arc = function (xloc, yloc, value, total, R) {
var alpha = 360 / total * value,
a = (90 - alpha) * Math.PI / 180,
x = xloc + R * Math.cos(a),
y = yloc - R * Math.sin(a),
path;
if (total == value) {
path = [
["M", xloc, yloc - R],
["A", R, R, 0, 1, 1, xloc - 0.01, yloc - R]
];
} else {
path = [
["M", xloc, yloc - R],
["A", R, R, 0, +(alpha > 180), 1, x, y]
];
}
return {
path: path
};
};
// inner ring
var circle = archtype.circle("50%", "50%", "40%").attr({
"stroke": "#2787d3",
"stroke-width": 1
});
// text
var text = archtype.text("95%", "50%", rate).attr({
'font-size': 14, 'font-family': 'Avenir',
"fill": "#2787d3"
});
// outer ring (filling)
var my_arc = archtype.path().attr({
"stroke": "#2787d3",
"stroke-width": 10,
arc: [100, 100, 0, 100, 50]
});
// animation of outer ring
my_arc.animate({
arc: [100, 100, 100, 100, 50]
}, 1000);
}
查看演示:http://jsfiddle.net/SUBn6/
目前,因为我没有使用百分比作为外环(填充),所以它没有以边框圆(内)为中心。
我遇到的另一个问题是“5%”这个数字。它需要跟随外环(填充),因为它从下到上填充......
有什么想法吗?谢谢。
【问题讨论】:
标签: javascript graph svg drawing raphael