0

I am using parse.com for my app for data storage etc... I have a quick question, when the user opens my app they are directed to their dashboard, in their dashboard there is a pie chart displaying data. I have in parse a class, in which a colour is an attribute, there are 6 different colours.

I want to display the colour values in the pie chart i.e. 6 red, 3 yellow, 2 blue etc. I researched this through google and came up with this https://www.parse.com/questions/can-i-manage-multiple-count-queries-in-a-single-call which states that it's not possible to have multiple count queries in a single call, however, this was posted 2 years ago and I'm wondering a. if there's been any advances on this since and b. if not what is the best way to go about this.

If I make 6 different calls, and I have to wait until I get the call back from the sixth count query before displaying the pie chart then there could be some delays which isn't good for user experience.

If anyone has any tips on this I'd appreciate it

1 Answer 1

7

I'd recommend creating a Cloud Code Function to query the counts in parallel and return the results in one response. I've used that successfully on a project using Parse.

Something like this:

Parse.Cloud.define("dashboard", function(request, response) {
    // create each query and start it
    var red = new Parse.Query("A").equalTo("colour", "red").count();
    var blue = new Parse.Query("A").equalTo("colour", "blue").count();

    // wait for them all to complete using Parse.Promise.when()
    // result order will match the order passed to when()
    Parse.Promise.when(red, blue).then(function(countOfRed, countOfBlue) {
        response.success({
            red: countOfRed,
            blue: countOfBlue
        });
    });
});
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your reply. I'm sorry I'm not following 100%. I have table/class 'A' in which I have a column colour and I want to get a total of each colour. Would you mind explaining a little further..it would be appreciated.
sorry to continue this but if I wanted to filter this based on the current user? Normally it would be query.equalTo("userId", userid); but with this promise I'm unsure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.