zrender icon indicating copy to clipboard operation
zrender copied to clipboard

Polyline图形points 数据更新之后 调用refresh()不起作用啊

Open shenzhirong opened this issue 9 years ago • 2 comments

var zr = zrender.init(document.getElementById('main'));

let polyline = new zrender.Polyline({
          shape: {
            points: [ [100,100],
                          [110,100],
                          [120,100] ]
          } ,
         style: {
                 stroke: ‘red’
           }
        })
zr.add(polyline);

setInterval(()=>{
    polyline.shape.points.push([Math.random()+ 120, 100]);
    zr.refresh()
},1000)

为什么只能画三个点的线,新增的点的线条刷新之后没有出现呢

shenzhirong avatar Nov 29 '17 02:11 shenzhirong

是调用的方法不对吗?

shenzhirong avatar Nov 29 '17 02:11 shenzhirong

@shenzhirong 更新完图形属性后需要再调用 dirty 方法标记图形需要更新

polyline.shape.points.push([Math.random()+ 120, 100]);
polyline.dirty()

或者调用 attr 方法也会自动标记

polyline.shape.points.push([Math.random()+ 120, 100]);
polyline.attr('shape', { points: polyline.shape.points })

pissang avatar Nov 29 '17 02:11 pissang