0

I have a nice JavaScript Pie chart that populates with set variable:

 var chartData = [{
            company: "Company #1",
            value: 260
        }, {
            company: "Company #2",
            value: 201
        }, {
            company: "Company #3",
            value: 65
        }, {
            company: "Company #4",
            value: 39
        }, {
            company: "Company #5",
            value: 19
        }, {
            company: "Company #6",
            value: 190
        }, {
            company: "Company #7",
            value: 54
            }, {
            company: "Company #8",
            value: 74
            }, {
            company: "Company #9",
            value: 98
            }, {
            company: "Company #10",
            value: 138
        }];

What I am trying to achieve is for the names of the company to be pulled from my MySQL database table [companies] and the values to be pulled from the same table with row [sales].

I have way more than 10 companies I do business with, but only want to chart the top 10.

Is this possible?

1 Answer 1

2

Select the top 10 companies from your database.

Put them into an array.

Then echo json_encode($myArray);

Sign up to request clarification or add additional context in comments.

3 Comments

@user1324759 Use the limit keyword in your query to limit the results to 10 at most.
The top companies may differ from month to month. I was hoping to find a way to populate this automatically, say from the most dollar amount showing in the database?
@Neal, Thank you sir, I will do some more looking and see if I can do what you suggest.

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.