简体   繁体   English

拉斐尔圆圈内的文字

[英]Text inside circle with Raphael

I am trying to replicate the following image with Raphael:我正在尝试使用 Raphael 复制以下图像:

在此处输入图片说明

So far I have only managed to get the circle working.到目前为止,我只设法让圆圈工作。 How do I get the faint gray outline (that shows the remainder) and the text within the circle.如何获得微弱的灰色轮廓(显示剩余部分)和圆圈内的文本。

var score = 883
var amount = score/1000 * 100;

var archtype = Raphael("canvas", 200, 100);
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
    };
};

var my_arc = archtype.path().attr({
    "stroke": "#00BB7B",
    "stroke-width": 7,
    arc: [50, 50, 0, 100, 30]
});

my_arc.animate({
    arc: [50, 50, amount, 100, 30]
}, 1500, "bounce");

Jsfiddle here: http://jsfiddle.net/1eh7dmgu/ Jsfiddle在这里: http : //jsfiddle.net/1eh7dmgu/

1) Balance you can show just put it under the green arc closed gray arc: 1)平衡你可以显示只是把它放在绿色弧线封闭的灰色弧线下:

var remainder = archtype.path().attr({
    "stroke": "#eeeeee",
    "stroke-width": 7,
    arc: [50, 50, 100, 100, 30]
});

2) To animate text counter can also use the manual attribute: 2)动画文本计数器也可以使用手动属性:

archtype.customAttributes.counter = function (counter) {
    return { text: counter, counter: counter }
}

[ http://jsfiddle.net/mwvLc0kb/ ] [ http://jsfiddle.net/mwvLc0kb/ ]

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

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