RGraph渐变应用于单个圆圈

时间:2012-05-01 16:18:36

标签: javascript jit radial-gradients

我正在使用RGraph,我需要用渐变创建圆圈, 所以他们看起来是3D球体。 我创建了一个名为blob的新节点类型,我已经实现了 代码如下。但是,渐变应用于整个 帆布。 不确定我能否解释一下,但有没有人可以提供帮助?

$jit.RGraph.Plot.NodeTypes.implement({
'blob': {
    render: function (node, canvas) {
        var pos = node.pos.getc(true),
        dim = node.getData("dim");

        // not sure about this code
        var ctx = canvas.getCtx();
        var radgrad = ctx.createRadialGradient(0, 0, dim, 0, 0, node.getPos().rho);
        radgrad.addColorStop(0, '#A7D30C');
        radgrad.addColorStop(0.9, '#019F62');
        radgrad.addColorStop(1, 'rgba(1,159,98,0)');
        ctx.fillStyle = radgrad;

        this.nodeHelper.circle.render("fill", pos, dim, canvas)
    },
    contains: function (node, canvas) {
        var pos = node.pos.getc(true),
        dim = node.getData("dim");
        return this.nodeHelper.circle.contains(pos, canvas, dim)
    }
}

});

非常感谢

伊万

1 个答案:

答案 0 :(得分:0)

我在这里得到了答案: Google Group

基本上,radgrad应该是这样的:

var radgrad = ctx.createRadialGradient(pos.x, pos.y, radius+20, pos.x-radius, pos.y,radius);