标题属性打破了sencha图表

时间:2014-09-26 12:46:59

标签: javascript extjs charts sencha-charts

我创建了一个带有两个Y轴的示例图表,在我给系列一个title属性后,它打破了图表。它在控制台上出现以下错误:

  

未捕获TypeError:Array.prototype.indexOf调用null或undefined

如果我们查看调用堆栈,我们会发现这发生在updateTitle()函数:

Error call stack

根据documentation系列确实有一个标题属性,为什么它会破坏图表?

Ext.application({
    name: 'Fiddle',

    launch: function() {
        var chart = new Ext.create('Ext.chart.CartesianChart', {
            renderTo: Ext.getBody(),
            width: 500,
            height: 500,
            legend: {
                docked: 'bottom'
            },
            "width": 740,
            "height": 440,
            "axes": [{
                "title": "Month",
                "type": "category",
                "position": "bottom",
            }, {
                "title": "Reputation",
                "type": "numeric",
                "position": "left",
            }, {
                "title": "Upvote",
                "type": "numeric",
                "position": "right",
            }],
            "series": [{
                "xField": "name",
                "yField": "data0",
                "yAxis": 1,
                "title": "Reputation gain",
                "type": "line"
            }, {
                "xField": "name",
                "yField": "data1",
                "yAxis": 2,
                "title": "Upvotes",
                "type": "line"
            }],
            "store": {
                "fields": ["name", "data0", "data1"],
                "data": [{
                    "name": "08/14",
                    "data0": 1567,
                    "data1": 2335
                }, {
                    "name": "09/14",
                    "data0": 1654,
                    "data1": 1246
                }, {
                    "name": "10/14",
                    "data0": 1777,
                    "data1": 1646
                }, {
                    "name": "11/14",
                    "data0": 2014,
                    "data1": 1456
                }, {
                    "name": "12/14",
                    "data0": 2562,
                    "data1": 2321
                }]
            }
        });
    }
});

1 个答案:

答案 0 :(得分:0)

您必须将title属性放在系列中的yAxis属性之前。所以定义你的系列如

"series": [{
    "title": "Reputation gain",//Have to be placed before yAxis.
    "xField": "name",
    "yField": "data0",
    "yAxis": 1,
    "type": "line"
}, {
    "title": "Upvotes",//Have to be placed before yAxis.
    "xField": "name",
    "yField": "data1",
    "yAxis": 2,
    "type": "line"
}],

这是我在支持论坛中报告的Sencha错误。由于某种原因,它们依赖于对象属性的顺序,因此将属性放入对象的顺序实际上很重要。