How to generate data for graphs

2

I'm doing a page that will have several types of graphics ... But my base is coming by jQuery, Example:

var wo = new Array();
var listItemEnumerator = this.customlist.getEnumerator();

while ( listItemEnumerator.moveNext() ) {
    var oListItem = listItemEnumerator.get_current();
    wo.push({ ID: oListItem.get_id(), Country: oListItem.get_item( 'Country' ) });
}

And with this object I will generate the graphs ... but if it were SQL, it would be easy, for example, to make a GROUP BY ... by the time I'm doing the comparisons for jQuery myself, an easier way, or some plugin that makes that selection in my database.

    
asked by anonymous 29.07.2014 / 14:38

1 answer

2

There is the library jLinq , I already used this library and it answered me very well, I did not use the part of GROUP BY (there is not in the documentation but if you look at the source there is the group () method), I have always used the filters and sort part of the library.

But checking here for part of group by also works correctly, even though we are not in the developer site demos, I've done some examples to illustrate how it works:

// filtro nomes de paises que iniciam "B" na lista
var result = jlinq.from(array)
.starts("country.nome", "B")
.select();

And an example of GROUP BY :

// Agrupa array por nome do pais
var resultGroup = jlinq.from(array)
.group("country.nome");

Follow this online example that best illustrates how it works.

Edit

According to @Thiago's comment, the question of how to specify the return fields (or format) in a query with the library jLinq . So I've also created an example for this situation:

// você consegue fazer um select no que você quer retornar
var result = jlinq.from(array)
.starts("country.nome", "B")
// o 'rec' é um alias da consulta
.select(function(rec) {
    // returnando um objeto no formato que você desejar
    return {
        id:rec.id,
    };
});

Or, even if you doubt @Thiago, you can even simplify and return only an Array of ids:

var result = jlinq.from(array)
   .starts("country.nome", "B")
   .select(function(rec) {
       return rec.id
});

Follow the online example of this new implementation.

    
29.07.2014 / 18:48