Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8652471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:18:54+00:00 2026-06-12T14:18:54+00:00

I asked this question earlier this morning here is my JSON file : [

  • 0

I asked this question earlier this morning
“here is my JSON file :

[
{
    "Week": "1145",
    "Sev_Logged": "3_major",
    "From": "IN1"
},
{
    "Week": "1145",
    "Sev_Logged": "4_minor",
    "From": "IN1"
},
{
    "Week": "1145",
    "Sev_Logged": "4_minor",
    "From": "IN1"
},
{
    "Week": "1145",
    "Sev_Logged": "4_minor",
    "From": "IN1"
},
{
    "Week": "1145",
    "Sev_Logged": "4_minor",
    "From": "IN1"
},
{
    "Week": "1145",
    "Sev_Logged": "4_minor",
    "From": "IN2"
},
{
    "Week": "1145",
    "Sev_Logged": "3_major",
    "From": "IN2"
},
];

I want to count the “from : IN1” field for each “week”, per example for week : 1145 i’d get : 3, and for “From : IN2” i’d get 2

Thanks”

Thank you VDP for your answer, so I did this :
My store is now like :

Ext.define('Metrics.store.GraphData', {
extend : 'Ext.data.Store',
model : 'Metrics.model.GraphData',
autoload : true,

proxy : {
    type : 'ajax',
    url : 'data/metrics_data.json',
    reader : {
        type : 'json',
        root : 'data',
        successProperty : 'success'
    }
},
//data : GraphData, //povide inline data or load using proxy
countBy: function(param){
    var count = {};
    this.each(function(item){
        var type = item.get(param);
        if (Ext.isDefined(count[type])){
            count[type]++;
        } else {
            count[type] = 1;
        }                               
    });
    return count;
}
});

And my model :

Ext.define('Metrics.model.GraphData', {
extend: 'Ext.data.Model',
//fields: ['week', 'sev']
fields : [ 
    {name: 'Week',  type: 'int'},
    {name: 'Sev_Logged',   type: 'string'},
    {name: 'From', type: 'string'}
]
});

Since i’m using extjs 4 with MVC model, I have made a controller wich controls the event of a button, right now it looks like this :

launchGraph : function(button){
console.log('clicked the apply button');
var chartStore = this.getGraphDataStore();
chartStore.load({
    callback: this.onGraphDataLoad,
    scope: this,
    console.log(chartStore.countBy("From"))
    });

But when I click the apply button I get this error in my controller :

"Uncaught SyntaxError: Unexpected token . "

And it points to the line :

 "console.log(chartStore.countBy("From"))"

It seems like i have an error in the referencing to my store. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:18:55+00:00Added an answer on June 12, 2026 at 2:18 pm

    If you are using the array you provide you can just use the mimikomi’s answer or a similar ExtJS version of it:

    here is a fiddle

    function countBy(data, param) {
        var count = {};
        Ext.each(data, function(item){
            var type = item[param];
            if (Ext.isDefined(count[type]))  {
                count[type]++;
            } else {
                count[type] = 1;
            }  
        });
        return count;
    }
    

    If you load that json from an external location it’s best practice to load it in a store. You define a model, a store and add ‘special’ functions to your store for example.

    Ext.define('Week', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'Week',  type: 'int'},
            {name: 'Sev_Logged',   type: 'string'},
            {name: 'From', type: 'string'}
        ]
    });
    
    var store = Ext.create('Ext.data.Store', {
        model: 'Week',
        data : data, //povide inline data or load using proxy
        countBy: function(param){
            var count = {};
            this.each(function(item){
                var type = item.get(param);
                if (Ext.isDefined(count[type])){
                    count[type]++;
                } else {
                    count[type] = 1;
                }                               
            });
            return count;
        }
    });
    
    var countObject = store.countBy("From");
    
    alert(Ext.encode(countObject));
    //chrome developper tools, safari, opera can show us the contents of objects in a log too. IE, FF however only tell us it is an object. (pretty useless)
    console.log(countObject);
    //you can chose you're favorite notation to retreve the value (but I hope you knew this, it's pretty basic javascript)
    console.log(countObject.IN1); 
    console.log(countObject['IN2']);
    

    Here is a fiddle.

    More info on loading json dynamically into a store via ajax (using a proxy)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question relates to this question which I asked earlier this week. The answer
I asked this question earlier today. After trying out suggestions from a few members,
I asked a question earlier this week and i got this statement as the
This relates to another question I asked earlier today. I built SVN 1.6.2 from
I asked this question earlier today and from the console, it works as expected.
So earlier I asked this question: JQuery Login Redirect. Code Included The php file
Note: This is an extension of an earlier question I asked here: Do additional
Note: This is an extension of an earlier question I asked here: Do additional
This question is related to my earlier question, asked here: How do I get
I'm reposting this question from an earlier post because when I originally asked it,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.