1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    25
    Vote Rating
    0
    skylinezpromise is on a distinguished road

      0  

    Default dynamic chart series : what's wrong with my store?

    dynamic chart series : what's wrong with my store?


    Hello I have a Python script that returns Json data which I load into my chart. The returned data looks like this :

    Code:
    {
        "data": [
            {
                "inAnalysis": 19, 
                "inQuest": 5, 
                "inDevelopment": 31, 
                "total": 56, 
                "inValidation": 1, 
                "Month": 1308
            }, 
            {
                "inAnalysis": 14, 
                "inQuest": 7, 
                "inDevelopment": 40, 
                "total": 63, 
                "inValidation": 2, 
                "Month": 1309
            }
        ], 
        "success": true, 
        "metaData": {
            "fields": [
                {
                    "name": "inAnalysis"
                }, 
                {
                    "name": "inQuest"
                }, 
                {
                    "name": "inDevelopment"
                }, 
                {
                    "name": "inValidation"
                }, 
                {
                    "name": "isDuplicate"
                }, 
                {
                    "name": "New"
                }, 
                {
                    "name": "total"
                }, 
                {
                    "name": "Month"
                }
            ]
        }
    }
    Knowing that the fields and data are dynamic and can change depending on the parameters sent by the user, the chart series will also change.
    So I have set up my store to retrieve the data and the metaData fields and give them to the chart as xFields and yFields, this is what I do :

    Code:
    Ext.define('Project.store.GraphData', {
        extend: 'Ext.data.Store',
        model: 'Project.model.GraphData',
        autoload: true,
        proxy: {
            type: "ajax", 
            reader: {
                type    : 'json',
                root    : 'data'
            },
            afterRequest: function(req, res) {
                 var chart = Ext.widget('drawchart');
                var fields = Ext.decode(req.operation.response.responseText).metaData.fields;
                var fieldNames = [];
                for (var i=0; i< fields.length; i++) {
                     console.log(fields[i].name);
                     fieldNames.push(fields[i].name);
                };
                // chart.axes.get("Month").fields =  'Month';
                //chart.axes.get('Backlog').fields = fieldNames;
                chart.series.addAll({
                        xField: ['Month'],
                        yField: fieldNames
                    });
                chart.redraw();    
            }
        }
    But this is not working, how can I do it please ??

  2. #2
    Sencha Premium Member Salakar's Avatar
    Join Date
    Aug 2013
    Location
    Nottingham
    Posts
    90
    Vote Rating
    4
    Salakar is on a distinguished road

      0  

    Default


    Can you explain how it's not working, does it give an error or, does it just not display anything, try change autoload: true, to this on your store:

    autoLoad: true,

  3. #3
    Sencha User
    Join Date
    Jul 2009
    Location
    Colorado Springs, CO
    Posts
    36
    Vote Rating
    1
    michaelbdavid is on a distinguished road

      0  

    Default


    What does your model look like? If you data is dynamic how can you know what to display? My guess is your model doesnt match your data?

  4. #4
    Sencha User
    Join Date
    Oct 2012
    Posts
    25
    Vote Rating
    0
    skylinezpromise is on a distinguished road

      0  

    Default empty Model

    empty Model


    My model is empty, I just have a model file with no fields :

    Code:
    Ext.define('Metrics.model.GraphData', {
        extend: 'Ext.data.Model'    
        });
    I have tried creating a model dynamically, and giving it the fields array like this (I have put this function in my store and I call it in the afterRequest function with the name 'GraphData'):
    Code:
    function modelFactory(name, fields) {
        return Ext.define(name, {
            extend: 'Ext.data.Model',
            fields: fields
        });
    }
    It didn't work. The chart doesn't show any data.
    Help please !

Thread Participants: 2

Tags for this Thread