How to generate data for Graphics

Asked

Viewed 655 times

2

I am making 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 graphics... but if it were SQL, it would be easy, for example, to make a GROUP BY... until now I am making the comparisons by jQuery even, but I was wondering if there is an easier way, or some plugin that make this selection in my base.

  • Don’t you get an object or something? Post it...

  • yes and there’s the code of how I build my object

  • You want to be able to make a GROUP BY (for example) in a javascript array easily?

  • Are you using any graphics library? Does this database that is coming by jQuery come from a database? If yes, you could group by in the database before generating the Javascript object.

  • yes, the GROUP BY also.. as I said, I will generate several graphs on the page, so I need something easy to handle my base by javascript

  • @Guilhermejsantos I can’t do the commands in the database =/ I don’t have access

  • Has the jLinno, I’ve used this library and it served me very well, I didn’t use the part of GROUP BY (but if you look at the source there’s a method group()), I always used but the part of filters and Sort.

  • @Fernando thanks, I’ll try!

  • @Fernando you q already used this library can help me so... I looked at an example on the page and this well: jlinq.from(data.users).select() in my case, just put my object(wo) in place of data.users?

  • @Thiago, edit the question and post an example of your array with some 10 items and what kind of operation you would like to do with it, which I see here how to do (if possible) and put as answer if it works. But to answer your question, yes, the data.users of the example is the list/array where the commands/filters/operations will be applied, in your case it seems to be the wo.

  • @Fernando in the post has exactly the code that I use to build my array of objects... but by the way I’m doing something wrong... the script is returning to the following msg: jLinq can only query arrays of Objects. I believe q is some adjustment in the array construction..

  • @Fernando now edited and put the complete code... once we arrive at a solution, just you answer the post q Mark as answer

  • @Thiago, this error occurs when you try to pass to jLine an object that is not an array. If you search your source for the error message you will see this check.

  • @Fernando but looking at my code, it seems to be all right in the construction of the object array...

Show 10 more comments

1 answer

2


There’s the library jLinno, I’ve used this library and it served me very well, I didn’t use the part of GROUP BY (but if you look at the source there is the group()) method, I’ve always used but the filter and Sort part of the library.

But checking here the part of group by also works correctly, although not in the demos of the developer site, I made some examples to illustrate its functioning:

// 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");

Follows this online example that best illustrates its functioning.

Edit

According to @Thiago’s comment, the question arose of how to specify the fields (or format) of the return in a query with the library jLinno. So I created an example for this situation as well:

// 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 as per @Thiago’s doubt, in the case of it 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
});

Follows the online example of that new implementation.

  • a doubt has arisen.... for ex: var result = linq.from(wo).starts("country.nome", "B").select(); console.log(result); this code will show the entire object, containing ID and Name... have I return only what I want? in case the ID

  • @Thiago, you can specify your select as demonstrated in the developer website (Refined Selecting Demo), I also made that example to better illustrate the use.

  • @Thiago, I’ve updated your answer?

  • yes, Voce helped me a lot! = D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.