2013-01-16 32 views
0

我无法为控制器中的系列图表创建'itemmouseup'事件的监听器。extjs4控制器中的MVC监听器

控制器:

init: function() { 
    this.control({ 
     'monthbalance > chart': { 
      render: this.onChartRendered, 
      itemmouseup : this.onChartClick 
     },   
    }); 
}, 

如果我插入 '鼠标松开' 事件而不是 'itemmouseup' 它工作正常。但我需要'itemmouseup'。我哪里错了?

谢谢。

更新与观点摘录:

 },{ 
     id: 'card-1', 
     xtype: 'chart', 
     store: 'MonthBalances', 
     title: 'This Year vs Previous Years', 
     theme: 'Category1', 
     legend: {position: 'right'}, 
     shadow: true, 
     axes: [{ 
      type: 'Numeric', 
      position: 'left', 
      fields: ['monthbalance','monthlastyear','monthpreviousyear'], 
      label: { 
       renderer: Ext.util.Format.numberRenderer('0,0') 
      }, 
      grid: true, 
      minimum: 0 
     },{ 
      type: 'Category', 
      position: 'bottom', 
      fields: ['month'] 
     }], 

     series: [{ 
      type: 'line', 
      title: 'this year', 
      itemId: 'lineone', 
      highlight: { 
       size: 7, 
       radius: 7 
      }, 
      axis: 'left', 
      xField: 'month', 
      yField: 'monthbalance', 
     // listeners: { 
     //  itemmouseup: function() { 
     //   console.log('itemmouseup-thisyear'); 
     //  } 
     // }, 
     },{ 
      type: 'line', 
      title: 'one year ago', 
      itemId: 'linetwo', 
      highlight: { 
       size: 7, 
       radius: 7 
      }, 
      axis: 'left', 
      xField: 'month', 
      yField: 'monthlastyear', 
     },{ 
      type: 'line', 
      id: 'linethree', 
      name: 'linethree', 
      itemId: 'linethree', 
      alias: 'widget.linethree', 
      title: 'two years ago', 
      highlight: { 
       size: 7, 
       radius: 7 
      }, 
      axis: 'left', 
      xField: 'month', 
      yField: 'monthpreviousyear', 

     }] 
    }]; 

回答

1

因为没有itemmouseup事件Chart。本次活动仅适用于扩展Ext.view.ViewExt.panel.Table

我认为你需要而不是直接访问该系列中的图表 持有的系列类。将您的控件设置为您在图表中使用的系列本身,而不是图表。 您可以通过设置系列图的ID属性来完成此操作,以便您可以将该控件绑定到该ID。

// untested but it should work 
init: function() { 
    this.control({ 
     '#your-id': { 
      itemmouseup : this.onChartClick 
     },   
    }); 
}, 
+0

好吧,我明白了。我把它当作一个监听器,放在我的视图中,就像在[docs]中一样(http://docs.sencha.com/ext-js/4-1/#!/api/Ext.chart.series。系列),但我真的想要在我的控制器中。它只能在视图中定义吗? – polarbear

+0

@polarbear我明白了。看我的编辑。 – sra

+0

我可以在我的控制台中通过'Ext.ComponentQuery.query('。chart')[0] .series.items'访问系列行,但无法弄清楚如何在我的控制器的'init'中访问它们。有任何想法吗?谢谢 – polarbear