具有多个字段ext js的折线图

时间:2014-04-10 14:57:53

标签: javascript extjs extjs4.1

我正在尝试模仿链接Link_here

中提供的图表

使用我的自定义数据。我把图表作为日期v / s温度。但我没有在图表上看到t1字段的折线图。

有人可以帮我弄清楚错误。

 var storea = Ext.create('Ext.data.Store', {
        model: 'WeatherPoint',
        data: [
            { temperature: 58, t1 : 23, date: new Date(2013, 1, 1, 8) },
            { temperature: 63, t1 : 52, date: new Date(2013, 1, 1, 9) },
            { temperature: 73, t1 : 56, date: new Date(2013, 1, 1, 10) },
            { temperature: 78, t1 : 67, date: new Date(2013, 1, 1, 11) },
            { temperature: 81, t1 : 87, date: new Date(2013, 1, 1, 12) }
        ]
    });



var chart = Ext.create('Ext.chart.Chart', {
            style: 'background:#fff',
            animate: true,
            store: storea,
            shadow: true,
            theme: 'Category1',
            legend: {
                position: 'right'
            },
            axes: [{
                type: 'Numeric',
                minimum: 0,
                position: 'left',
                fields: ['temperature', 't1'],
                title: 'Number of Hits',
                minorTickSteps: 1,
                grid: {
                    odd: {
                        opacity: 1,
                        fill: '#ddd',
                        stroke: '#bbb',
                        'stroke-width': 0.5
                    }
                }
            }, {
                type: 'Category',
                position: 'bottom',
                fields: ['date'],
                title: 'Month of the Year'
            }],
            series: [{
                type: 'line',
                highlight: {
                    size: 7,
                    radius: 7
                },
                axis: 'left',
                xField: 'date',
                yField: 'temperature',
                markerConfig: {
                    type: 'cross',
                    size: 4,
                    radius: 4,
                    'stroke-width': 0
                }
            }, {
                type: 'line',
                highlight: {
                    size: 7,
                    radius: 7
                },
                axis: 'left',
                smooth: true,
                xField: 'date',
                yField: 't1',
                markerConfig: {
                    type: 'circle',
                    size: 4,
                    radius: 4,
                    'stroke-width': 0
                }
            }, {
                type: 'line',
                highlight: {
                    size: 7,
                    radius: 7
                },
                axis: 'left',
                smooth: true,
                fill: true,
                xField: 'name',
                yField: 'data3',
                markerConfig: {
                    type: 'circle',
                    size: 4,
                    radius: 4,
                    'stroke-width': 0
                }
            }]
        });


    var win = Ext.create('Ext.Window', {
        width: 800,
        height: 600,
        minHeight: 400,
        minWidth: 550,
        hidden: false,
        maximizable: true,
        title: 'Line Chart',
        renderTo: Ext.getBody(),
        layout: 'fit',
        tbar: [{
            text: 'Save Chart',
            handler: function() {
                Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function(choice){
                    if(choice == 'yes'){
                        chart.save({
                            type: 'image/png'
                        });
                    }
                });
            }
        }, {
            text: 'Reload Data',
            handler: function() {
                // Add a short delay to prevent fast sequential clicks
                window.loadTask.delay(100, function() {
                    storea.loadData(generateData(8));
                });
            }
        }],
        items: chart
    });

这是我用上面的代码得到的:

enter image description here

1 个答案:

答案 0 :(得分:1)

当我将fields: ['temperature', 't1', 'date'],添加到商店时,它对我有效。 http://jsfiddle.net/x_window/Kce8n/