在Ext js中重新加载不起作用

时间:2014-07-18 12:03:24

标签: javascript extjs

我需要的是什么:

示例有所帮助,但我无法在饼图中重新加载数据。这是我的代码:

   Ext.onReady(function () {
    store.loadData(generateData());
    var donut = false,
    panel1 = Ext.create('widget.panel', {
    width: 800,
    height: 600,
    title: 'Semester Trends',
    renderTo: Ext.getBody(),
    layout: 'fit',
    tbar: [{
        text: 'Reload Data',
        handler: function() {
    Ext.Msg.alert("click");
            store.loadData(generateData());
        }
    },
{
 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'
                    });
                }
            });
        }
    },

{
        enableToggle: true,
        pressed: false,
        text: 'Donut',
        toggleHandler: function(btn, pressed) {
            var chart = Ext.getCmp('chartCmp');
            chart.series.first().donut = pressed ? 35 : false;
            chart.refresh();
        }
    }],
    items: {
        xtype: 'chart',
        id: 'chartCmp',
        animate: true,
        store: store,
        shadow: true,
        legend: {
            position: 'right'
        },
        insetPadding: 60,
        theme: 'Base:gradients',

        series: [{
            type: 'pie',
            field: 'temperature',
            showInLegend: true,
            donut: donut,
            tips: {
              trackMouse: true,
              width: 140,
              height: 28,
              renderer: function(storeItem, item) {
                //calculate percentage.
                var total = 0;
                store.each(function(rec) {
                  total += rec.get('date');
                });
                this.setTitle(storeItem.get('temperature') + ': ' + storeItem.get('date') );
              }
            },
            highlight: {
              segment: {
                margin: 20
              }
            },
           label: {
                field: 'temperature',
                display: 'rotate',
                contrast: true,
                font: '18px Arial'
            }
        }]
    }
});
});

我还使用了一个sencha示例网址:http://try.sencha.com/extjs/4.0.7/examples/charts/pie/viewer.html但它无效。

我必须在图表中重新加载数据。我的数据已加载到图表中,但无法重新加载。

example-data.js代码:

 Ext.onReady(function() {

window.generateData = function(){
    var data = [];

        data.push(
    { temperature: 86, date: new Date(2014, 1, 4, 8) },
    { temperature: 20, date: new Date(2014, 1, 5, 7) },
    { temperature: 75, date: new Date(2014, 1, 1, 11) },
    { temperature: 10, date: new Date(2014, 1, 1, 7) },
    { temperature: 46, date: new Date(2014, 1, 1, 12) }
    );

    return data;

      };




window.store = Ext.create('Ext.data.JsonStore', {
    fields: ['temperature', 'date'],
    data: generateData()
});


  window.loadTask = new Ext.util.DelayedTask();
});

1 个答案:

答案 0 :(得分:0)

var chartId = Ext.getStore('myStore'); ChartId.refresh();

尝试一次

相关问题