【问题标题】:Creating a chart with Sencha Touch 2使用 Sencha Touch 2 创建图表
【发布时间】:2014-04-24 09:10:45
【问题描述】:

这是我的观点

(图表相关代码在创建的星号行结束)

Ext.define('denovoeye.view.OcularPressure', {
    extend: 'Ext.navigation.View',
    xtype: 'ocularPressure',
    config: {
        scrollable: {
            direction: 'vertical'
        },
        items: [{
                xtype: 'container',
                fullscreen: true,
                layout: 'vbox',
                items: [{
                        style: 'background-color:#72D2D4;',
                        flex: 1,
                        items: [{
                                xtype: 'component',
                                flex: 1,
                                html: '<div style="text-align:left;padding : 20px 0px 0px 20px;color:#120963;"> INTRA OCULAR PRESSURE</div>',
                            }, {
                                xtype: 'chart',
                                store: 'OcularPressure',
                                flex: 5,
                                layout: 'fit',
                                animate: false,
                                interactions: ['panzoom'],
                                series: [
                                    {
                                        type: 'line',
                                        xField: 'name',
                                        yField: 'g1',
                                        title: 'Line1',
                                        style: {
                                            lineWidth: 2,
                                            stroke: 'rgba(0,40,170,0.7)'
                                        }
                                    },
                                    {
                                        type: 'line',
                                        xField: 'name',
                                        yField: 'g2',
                                        title: 'Line2',
                                        style: {
                                            lineWidth: 2,
                                            stroke: 'rgba(80,40,170,0.7)'
                                        }
                                    }
                                ],
                                axes: [
                                    {
                                        type: 'numeric',
                                        position: 'left',
                                        grid: true
                                    },
                                    {
                                        type: 'category',
                                        position: 'bottom',
                                        grid: true,
                                        visibleRange: [0, 0.5]
                                    }
                                ]
                            }, 
        //******************************************************************************************
                            {
                                xtype: 'container',
                                flex: 1,
                                layout: 'hbox',
                                style: 'margin:20px 20px 20px 20px;',
                                items: [{
                                        html: ' ',
                                        flex: 1.25
                                    }, {
                                        html: '<div style="text-align:left;padding : 20px 0px 0px 20px;color:#120963;">&#x025FC Right Eye</div>',
                                        flex: 1
                                    }, {
                                        html: '<div style="text-align:left;padding : 20px 0px 0px 20px;color:#ffffff;">&#x025FC Left Eye</div>',
                                        flex: 1
                                    }]
                            }]
                    },
                    {
                        style: 'background-color: #ffffff;',
                        flex: 1,
                        items: [{
                                xtype: 'container',
                                flex: 1,
                                layout: 'hbox',
                                style: 'margin:20px 20px 10px 20px;border-bottom:1px solid #c7c7c7;',
                                items: [{
                                        xtype: 'container',
                                        flex: 1.25,
                                        html: ' '
                                    }, {
                                        xtype: 'container',
                                        flex: 1,
                                        html: '<div style="border-bottom:1px solid white;text-align:left;margin : 20px 20px 0px 20px;color:#120963;"><b>Right Eye</b></div>'
                                    }, {
                                        xtype: 'container',
                                        flex: 1,
                                        html: '<div style="border-bottom:1px solid white;text-align:left;margin : 20px 20px 0px 20px;color:#120963;"><b>Left Eye</b></div>'
                                    }]
                            }, {
                                xtype: 'container',
                                flex: 1,
                                layout: 'hbox',
                                style: 'margin:0px 20px 0px 10px;border-bottom:1px solid #c7c7c7;',
                                items: [{
                                        xtype: 'container',
                                        layout: 'hbox',
                                        flex: 1.3,
                                        html: '<div style="border-bottom:1px solid white;text-align:left;padding : 20px 20px 0px 20px;color:#120963;">APR 4,2014</div>'
                                    }, {
                                        xtype: 'container',
                                        layout: 'hbox',
                                        flex: 1,
                                        html: '<div style="border-bottom:1px solid white;text-align:left;padding : 20px 20px 0px 20px;color:#120963;">10mmHG</div>'
                                    },
                                    {
                                        xtype: 'container',
                                        layout: 'hbox',
                                        flex: 1,
                                        html: '<div style="border-bottom:1px solid white;text-align:left;padding : 20px 20px 0px 20px;color:#120963;">12mmHG</div>'
                                    }]
                            },
                            {
                                xtype: 'container',
                                flex: 1,
                                layout: 'hbox',
                                style: 'margin:0px 20px 0px 10px;border-bottom:1px solid #c7c7c7;',
                                items: [{
                                        xtype: 'container',
                                        layout: 'hbox',
                                        flex: 1.3,
                                        html: '<div style="border-bottom:1px solid white;text-align:left;padding : 20px 20px 0px 20px;color:#120963;">APR 4,2014</div>'
                                    }, {
                                        xtype: 'container',
                                        layout: 'hbox',
                                        flex: 1,
                                        html: '<div style="border-bottom:1px solid white;text-align:left;padding : 20px 20px 0px 20px;color:#120963;">10mmHG</div>'
                                    },
                                    {
                                        xtype: 'container',
                                        layout: 'hbox',
                                        flex: 1,
                                        html: '<div style="border-bottom:1px solid white;text-align:left;padding : 20px 20px 0px 20px;color:#120963;">12mmHG</div>'
                                    }]
                            },
                            {
                                xtype: 'container',
                                flex: 1,
                                layout: 'hbox',
                                style: 'margin:0px 20px 0px 10px;border-bottom:1px solid #c7c7c7;',
                                items: [{
                                        xtype: 'container',
                                        layout: 'hbox',
                                        flex: 1.3,
                                        html: '<div style="border-bottom:1px solid white;text-align:left;padding : 20px 20px 0px 20px;color:#120963;">APR 4,2014</div>'
                                    }, {
                                        xtype: 'container',
                                        layout: 'hbox',
                                        flex: 1,
                                        html: '<div style="border-bottom:1px solid white;text-align:left;padding : 20px 20px 0px 20px;color:#120963;">10mmHG</div>'
                                    },
                                    {
                                        xtype: 'container',
                                        layout: 'hbox',
                                        flex: 1,
                                        html: '<div style="border-bottom:1px solid white;text-align:left;padding : 20px 20px 0px 20px;color:#120963;">12mmHG</div>'
                                    }]
                            }]
                    }
                ]
            }]
    }
});

这是我的模特:

Ext.define('denovoeye.model.OcularPressure', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
            {name: 'name', type: 'auto'},
            {name: 'g1', type: 'int'},
            {name: 'g2', type: 'int'},
            {name: 'g3', type: 'int'},
            {name: 'g4', type: 'int'},
            {name: 'g5', type: 'int'}

        ]
    }
});

这是我的商店:

Ext.define('denovoeye.store.OcularPressure', {
    extend: 'Ext.data.Store',
    config: {
        model: 'denovoeye.model.OcularPressure',
        data: [
            {"name": "Item-0", "g1": 18.341524994680185, "g2": 0.04297258032918805, "g3": 22.351114037029276, "g4": 10.501821959142115, "g5": 18.422488416954124},
            {"name": "Item-2", "g1": 1.9082894708999651, "g2": 5.729225849931112, "g3": 14.809082259901247, "g4": 38.935629377514275, "g5": 2.7729804343737},
            {"name": "Item-3", "g1": 21.372004559042896, "g2": 2.131323680889345, "g3": 12.98075950737056, "g4": 63.8279558143009, "g5": 18.852890370148263},
            {"name": "Item-4", "g1": 2.678644589238747, "g2": 8.533478458163483, "g3": 4.442247207672851, "g4": 87.39642008886551, "g5": 27.236700916073737},
        ]
    }
});

我最终遇到了这个错误: Uncaught TypeError: Cannot call method 'getData' of null

任何人都可以看看这个并帮我渲染图表吗?

【问题讨论】:

    标签: javascript extjs sencha-touch-2 sencha-charts


    【解决方案1】:

    这只是一个错字:-

    将商店名称从 "OcularPressure" 更改为 "OcularPressures" 并在视图中替换它。还可以通过添加视图中所需的所有必需文件来删除警告。

    【讨论】:

    • 我不明白,为什么要改名?我已正确提供了所有商店和视图名称,还是我遗漏了什么?
    • 对不起,错误是我这边的。我运行了你的代码,但它没有给我任何错误。也许清除浏览器的缓存并再次运行它
    • 它对我来说仍然有同样的错误。不过我看不出有什么问题。
    • 是的,它在我这边工作得很好。那么您可以做的最后一件事是创建另一个项目并复制代码。我不能再帮你了,对不起。
    • 图表作为输出出现?
    【解决方案2】:

    我找到了解决方案。 我只需要添加图表的高度和宽度。

        width:400px;
        height:400px;
        xtype: 'chart',    
        store: 'OcularPressure',
        flex: 5,
        layout: 'fit',
        animate: false,
        interactions: ['panzoom']
    

    【讨论】:

      猜你喜欢
      • 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
      相关资源
      最近更新 更多