简体   繁体   English

径向图上的拉斐尔夏娃动画

[英]raphael eve animation on a radial chart

Can someone have a look at this, and see why the count isnt working for the first chart.有人可以看看这个,看看为什么计数不适用于第一个图表。

$(document).ready(function() {

    display_chart(54,'overall');
    display_chart(55,'test');

});


function display_chart(amount,div){

    var paper = Raphael(document.getElementById(div), 500, 500);
    paper.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 backCircle = paper.circle(150, 100, 70).attr({
        "stroke": "#d0e8cf",
        "stroke-width": 25
    });

    var theArc = paper.path().attr({
        "stroke": "#66cc66",
        "stroke-width": 25,
        arc: [50, 100, 0, 100, 70]
    });


    //event fired on each animation frame
    eve.on("raphael.anim.frame.*", onAnimate);

    //text in the middle
    theText = paper.text(150, 100, "0%").attr({
        "font-size": 36,
        "font-face" : "Droid Sans",
        "fill": "#666666",
        "font-weight": "bold"
    });

    //the animated arc
    theArc.rotate(180, 100, 100).animate({
        arc: [50, 100, amount, 100, 70]
    }, 1900, function() {
        //when the animation is done unbind
        eve.unbind("raphael.anim.frame.*", onAnimate);
    });

    function onAnimate() {
        var howMuch = theArc.attr("arc");
        theText.attr("text", Math.floor(howMuch[2]) + "%");
    }

}

http://jsfiddle.net/pVcSb/ http://jsfiddle.net/pVcSb/

you need to declare your var "theText" with 'var' keyword你需要用'var'关键字声明你的var“theText”

var theText = ...

use "use strict" to avoid this kind of errors使用“use strict”来避免这种错误

http://jsfiddle.net/pVcSb/1/ http://jsfiddle.net/pVcSb/1/

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

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