Search code examples
sencha-touchextjssencha-charts

Sencha Touch Charts not rendering


I am quite new to sencha touch and sencha touch charts, and I am having a little troubling integrating a chart in one of my views. I probably am missing something obvious here. Here is how I set up the chart variable.

var chart2 = new Ext.chart.Chart({
    width: 500,
    height: 300,
    animate: true,
    store: testStore,
    theme: 'Base:gradients',
    series: [{
        type: 'pie',
        angleField: 'data1',
        label: {
            field: 'name',
            display: 'rotate',
            contrast: true,
            font: '18px Arial'
        }
    }]
});

A simple pie chart loading its data store from

var testStore = new Ext.data.JsonStore({
fields: ['name', 'data1', 'data2', 'data3', 'data4', 'data5'],
data: [
    {'name':'metric one', 'data1':10, 'data2':12, 'data3':14, 'data4':8, 'data5':13},
    {'name':'metric two', 'data1':7, 'data2':8, 'data3':16, 'data4':10, 'data5':3},
    {'name':'metric three', 'data1':5, 'data2':2, 'data3':14, 'data4':12, 'data5':7},
    {'name':'metric four', 'data1':2, 'data2':14, 'data3':6, 'data4':1, 'data5':23},
    {'name':'metric five', 'data1':27, 'data2':38, 'data3':36, 'data4':13, 'data5':33}
]
});

And here is my ChartViewPanel

SS.views.chartView = Ext.extend(Ext.Panel, {

fullscreen: true,
initComponent: function() {

    console.log("Initializing Chart View");

    this.refreshButton = new Ext.Button({
        text: 'Refresh',
        ui: 'action',
        handler: function() {
            console.log("Refresh button is clicked");
        },
        scope: this
    });

    this.topToolbar = new Ext.Toolbar({
        title: 'Chart View',
        items: [
            { xtype: 'spacer'},
            this.refreshButton
        ]
    });

    this.dockedItems = [this.topToolbar];

    this.items = [chart2];

    console.log(chart);

    SS.views.chartView.superclass.initComponent.call(this);
}
});

The top bar is being rendered but not the chart. The javascript console doesn't show me any error either. At which point have I gone wrong? Many thanks


Solution

  • You need to add "renderTo" in chart2. See http://docs.sencha.com/touch-charts/1-0/#!/api/Ext.chart.Chart