Javascript 重绘RGRAPHSVG半圆形图

Javascript 重绘RGRAPHSVG半圆形图,javascript,svg,rgraph,Javascript,Svg,Rgraph,我有一个带有SVG半圆形RGraph图表的Web应用程序。这些SVG图形的初始绘制进展顺利。我想用一个新值动态更新其中一些图表。我在答案()中看到,您首先需要清除前面的svg,但是在它之后直接运行grow/draw函数是行不通的。图形将被清除,但不会使用grow函数重新绘制。可能是异步问题。。以前有人遇到过这种行为吗?我并不真的希望添加一个超时或类似的方法,希望我能用rgraphapi本身解决它。这就是我所拥有的: if (this._gauge){ // If the chart ha

我有一个带有SVG半圆形RGraph图表的Web应用程序。这些SVG图形的初始绘制进展顺利。我想用一个新值动态更新其中一些图表。我在答案()中看到,您首先需要清除前面的svg,但是在它之后直接运行grow/draw函数是行不通的。图形将被清除,但不会使用grow函数重新绘制。可能是异步问题。。以前有人遇到过这种行为吗?我并不真的希望添加一个超时或类似的方法,希望我能用rgraphapi本身解决它。这就是我所拥有的:

if (this._gauge){
    // If the chart has already been created then clear the SVG
    RGraph.SVG.clear(this._gauge.svg);
} else {
    // if using SVG target the div domNode instead of the canvas element
    this._gauge = new RGraph.SVG.SemiCircularProgress ({
        id: this.domNode.id,
        min: minValue,
        max: maxValue,
        value: value,
        options: this._options
    });
}
this._gauge.grow({  frames: this.easingDuration,
                    callback: dojoLang.hitch(this,function (){
                        // for no apparent reason, if multiple SVG gauges are added, the callback is only effective for one of the gauges randomly.
                        // a timeout fixes this...
                        window.setTimeout(dojoLang.hitch(this,function(){
                             this._gauge.path.onclick = dojoLang.hitch(this, function (e){
                                 this._execMF(this.onClickMF,this._contextObj.getGuid());
                             });
                             this._gauge.path.onmousemove = dojoLang.hitch(this, function (e){
                                 e.target.style.cursor = 'pointer';
                             });
                        }),1000);

                    })
});

我无法复制你的问题。您是否尝试过使用画布版本的半圆进度条?如果你问我,画布更容易使用

在切换之前,您可以尝试将调用从RGraph.SVG.clear()更改为RGraph.SVG.reset(),看看是否有任何效果

画布版本的页面如下所示:

<html>
<head>
    <script src="RGraph.common.core.js" ></script>
    <script src="RGraph.common.dynamic.js" ></script>
    <script src="RGraph.semicircularprogress.js" ></script>

    <meta name="robots" content="noindex,nofollow" />
</head>
<body>

    <canvas id="cvs" width="600" height="300">[No canvas support]</canvas>

    <script>
        scp = new RGraph.SemiCircularProgress({
            id: 'cvs',
            min: 0,
            max: 10,
            value: 8,
            options: {
            }
        }).grow(null, function ()
        {
            alert('In First grow effects callback');

        })
        //.on('click', function (e)
        //{
        //    $a('Inside the click event that sets a random value');
        //    scp.value = RGraph.random(0,10);
        //    scp.grow();
        //});

        setTimeout(function ()
        {
            scp.value = 4;
            scp.grow(null, function ()
            {
                alert('In second grow effects callback');
            });
        }, 3000);
    </script>
</body>
</html>

[无画布支持]
scp=新的RGraph.semicularprogress({
id:'cvs',
分:0,,
最高:10,
数值:8,
选项:{
}
}).grow(null,函数()
{
警报(“在第一次增长效果回调中”);
})
//.on('click',函数(e)
//{
//$a('在设置随机值的单击事件内');
//scp.value=RGraph.random(0,10);
//scp.grow();
//});
setTimeout(函数()
{
scp.value=4;
scp.grow(null,函数()
{
警报(“在第二次增长效果回调中”);
});
}, 3000);

你好,Richard,感谢您的快速回复!实际上,我已经实现了canvas和svg图表,并且确实需要这两种实现。对于canvas,一切都按预期进行。您真的不能为SVG复制它吗?因此,首先使用.grow()函数创建一个图表,然后使用.clear()删除svg,然后再次执行.grow(),结果成功了?我尝试了重置选项,但它给出了:“RGraph.svg.Reset不是一个函数”。我确实看到rhe函数存在于RGraph对象中,但不存在于RGraph.SVG上。也许我使用的是旧版本的API?但在我使用的RGraph文件中,似乎找不到名为“version”的属性。我可能找不到正确的位置..reset函数肯定在RGraph.svg.common.core.js中。您可以在此处看到该文件:只需搜索“RGraph.SVG.reset=”如果您的版本中没有该函数,您可以尝试更新(此版本为5.21)。顺便说一下,您可以只更新一个文件。如果要升级,您必须更新页面上使用的所有SVG库。结果证明,RGraph库的升级成功了。我从2017年开始实施了一个版本,当时我在2018年构建了这个小部件。也许在RGraph对象中添加版本属性是个好主意?通过这种方式,很容易看到实现正在哪个版本上运行。我还可以去掉grow函数中的超时:)。无论如何,谢谢你的帮助!