1

我正在制作的折线图有一些问题。

我正在制作它,它会每秒自动更新一次,它将采用“Ping Time”文本字段中的值,然后将其放在图表上,在下一个“分钟”索引处。

然而,问题在于,当图表更新时,它不会正确刷新轴。你可以在这里看到这个:

http://jsfiddle.net/HTj5Q/71/

相关的代码片段将是图表创建,

Ext.create('Ext.chart.Chart',{
        renderTo:Ext.getBody(),
        id:'ChartTest',
        xtype: 'chart',
        width: 400,
        height:300,
        store: testStore,
        axes:[
            {
                title:'Ping Time',
                type: 'Numeric',
                position: 'left',
                grid:true,
                fields: ['ping'],
            },
            {
                title:'Minutes',
                type: 'Numeric',
                position: 'bottom',
                grid:true,
                fields:['id'],
                minimum:0,
            }
        ],
        series: [
             {
                 type:'line',
                 xField:'id',
                 yField:'ping',
                tips: {
                trackMouse: true,
                width: 80,
                height: 40,
                renderer: function(storeItem, item) {
                    this.setTitle(storeItem.get('id'));
                    this.update(storeItem.get('ping'));
                }
            }
             }
        ],
});

以及令人耳目一新的代码

var task = Ext.TaskManager.start({
 run: function () {
     min=min+1;
    // max=max+1;
    // Ext.getCmp('ChartTest').axes.items[1].maximum=max;
     Ext.getCmp('ChartTest').axes.items[1].minimum=min;
     test= Ext.getCmp('PingTime').getValue();
     temp = temp+1;
     Ext.getCmp('display').setValue('Temp = '+temp+' Test = '+test);   

     testStore.add({id:temp,ping:test});
     var rec=  testStore.getAt(0);
     Ext.getCmp('display2').setValue('rec is '+rec.get('id'));
     if(rec.get('id')<temp-8)
     {
         testStore.remove(rec);
     }
     Ext.getCmp('ChartTest').redraw();

     },
     interval: 2000
 });
4

1 回答 1

0

尝试使用

Ext.getCmp('ChartTest').surface.removeAll();

在 redraw() 方法之前。

这不是一个完整的解决方案,因为仍然存在一些问题。例如,如果您显着更改“Ping time”文本字段中的值,Y 轴将被破坏。此外,它可能无法在所有浏览器中正常工作,但我想这些附加信息可能会帮助您找到最终解决方案。

于 2014-01-22T08:11:04.123 回答