【问题标题】:Creating a chart with Sencha Touch 2?使用 Sencha Touch 2 创建图表?
【发布时间】:2013-05-27 15:28:11
【问题描述】:

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

我添加了一个这样的视图,并插入了一个图表,我在几个网站上看到它:

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'
],

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: extjs charts touch


    【解决方案1】:

    typextype等是区分大小写的,库中的都是小写的。

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

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

    xtype: 'graph',
    

    【讨论】:

    • 谢谢,现在可以了!我使用 main.js 中的 xtype 来查看网站是这样的: { xtype: 'graph' title: 'Graph', iconCls: 'compose' } 是不是错了?
    • 要在 Ext4 或 Touch 中创建新的 xtype,您应该在定义中使用 aliasalias: widget.graph。然后,您可以使用例如Ext.widget({title: 'Graph', xtype: 'graph'})Ext.widget({xtype: 'panel', items: [{xtype: 'graph'}]}) 作为项目。不过,不确定这对主视图是否非常有用。
    【解决方案2】:

    您是否在此处添加了 Sencha Touch 2 Charts 2 Beta?如果是这样,你到底是怎么做到的?请下载后从头开始——我是菜鸟:)

    【讨论】:

    • 这也是我使用 Sencha 的第一个项目。我只下载了 Sencha Touch。没有针对图表的特定内容。
    • 真的吗?甚至只有付费或演示可用的完整 Sencha Touch Bundle?有人可以澄清一下吗?我认为图表是一个额外的包?!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多