2013-05-27 71 views
0

我正在尝试将图表添加到我的Sencha Touch应用程序中。用Sencha Touch 2创建图表?

我加入了这样的观点,并插入图表我怎么看见它的一对夫妇的网站:

Ext.define('dergraph.view.Graph', { 
    extend: 'Ext.Container', 
    xtype: 'graph', 
    requires: [ 
     'Ext.TitleBar' 
    ], 
    config: { 
     tabBarPosition: 'bottom', 
     layout: 'fit', 

     items: [ 
      { 
       xtype: 'chart', 
       animate: true, 
       store: 'dergraph.store.PhoneBook', 
       legend: { 
        position: 'right' 
       }, 

       axes: [{ 
         type: 'Category', 
         fields: ['firstName'], 
         position: 'bottom', //x-axis 
         title: 'Category' 
        }, { 
         type: 'Numeric', 
         fields: ['value'], 
         position: 'left', //y-axis 
         title: 'Value' 
       }] 
      } 
     ] 
    } 
}); 

但现在我在浏览器的控制台中的错误有:未捕获的错误: Ext.createByAlias]无法创建无法识别别名的实例:axis.Category。

这是app.js我需要部分:

requires: [ 
     'Ext.MessageBox', 
     'Ext.dataview.List', 
     'Ext.chart.Chart', 
     'Ext.chart.axis.Numeric', 
     'Ext.chart.axis.Category' 
], 

有人可以帮我吗?

回答

1

type,xtype等区分大小写,库中的全部都是小写。

因此,将type: 'Category'更改为type: 'category'type: 'Numeric'type: 'numeric',并且您的代码将运行。

你也应该阅读有关xtype的文档。该选项用于指示要创建的组件的类型,而不必自己使用new关键字(允许延迟初始化)。 xtype选项仅在您想要对象实例化的对象的上下文中有意义,而不是您在定义的。因此,您的代码中的这一行没有任何影响:

xtype: 'graph', 
+0

谢谢,它现在可以工作! 我以前在main.js中的xtype查看该网站是这样的: { 的xtype: '曲线' 标题: '图表', iconCls: '撰写' } 是不是错了? – torhoehn

+0

要在Ext4或Touch中创建新的xtype,您应该在定义中使用[别名](http://docs.sencha.com/touch/2.2.1/#!/api/Ext.Class-cfg-alias) :'别名:widget.graph'。然后,你可以使用例如'Ext.widget({title:'Graph',xtype:'graph'})'或者作为item,'Ext.widget({xtype:'panel',items:[{xtype :'graph'}]})'。不过,不确定这对主视图非常有用。 – rixo

0

您是否在此包含Sencha Touch 2图表2测试版?如果是这样,你到底是怎么做到的?请从下载后开始 - 我是一名新手:)

+0

这也是我与Sencha的第一个项目。我只下载了Sencha Touch。没有特定的图表。 – torhoehn

+0

真的吗?甚至没有完整的Sencha Touch Bundle,只有付费或作为演示?有人可以澄清这一点吗?我以为图表是一个额外的包?! – flip321