简体   繁体   English

ExtJS 4.2-图表重绘,仍然看到旧标签

[英]ExtJS 4.2 - Chart Redraw, still see old labels

I have some problem with my line chart that I am making. 我正在制作的折线图存在一些问题。

I am making it so it will automatically update every second, and it will take the value in the "Ping Time" text field, then place it onto the chart, at the next "Minute" index. 我正在这样做,它将每秒自动更新一次,它将在“ Ping Time”文本字段中获取值,然后将其放在图表上的下一个“ Minute”索引处。

What is wrong however, is that, when the chart updates, it would not properly refresh the axis. 但是,错误的是,当图表更新时,将无法正确刷新轴。 You can see this in action here: 您可以在这里看到实际效果:

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

The concerned pieces of code would be the chart creation, 有关的代码片段将是图表的创建,

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'));
                }
            }
             }
        ],
});

As well as the refreshing code 以及刷新代码

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
 });

Try to use 尝试使用

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

before redraw() method. 在redraw()方法之前。

It's not a complete solution because of there are some issues are still remained. 由于仍然存在一些问题,因此它不是一个完整的解决方案。 For instance if you change a value in the "Ping time" textfield significantly Y axis will be broken. 例如,如果您在“ Ping时间”文本字段中更改值,则Y轴将被严重破坏。 Moreover it may not works properly in the all browsers but I guess this additional information may help you to find out a final solution. 此外,它可能无法在所有浏览器中正常工作,但是我想这更多的信息可能会帮助您找到最终的解决方案。

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

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