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

  • Home
  • SEARCH
  • 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 7980949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:13:38+00:00 2026-06-04T10:13:38+00:00

I am attempting to make a pie chart using a php file that gets

  • 0

I am attempting to make a pie chart using a php file that gets the information from MySQL, JSON encodes it, and then sends it to my JS file to make the pie chart. I have looked at most of the other questions posted here and none of them help me at all. I have attempted to re-qrite my code to match ones that seem to fit, but nothing is working.
My php file is:

$shelvDate = $_POST['shelvDate'];
$x = 0;

// get information from database for shelving chart
$shelv = $conn -> query ("SELECT sum(quantity) as qty, date_process, created_by, first_name from inventory LEFT JOIN users on users.user_id =inventory.created_by
    WHERE date_process = '$shelvDate' GROUP BY created_by" );
$num_rows = $shelv->num_rows;

if($num_rows > 0){
    while($row = $shelv->fetch_assoc()) {
        if($row['qty'] > 0){
            $qtyArray[$x] = $row['qty'];
            $nameArray[$x] = $row['first_name'];
        }
        $x++;

        $pairs = array('first_name' => $nameArray, 'qty' => $qtyArray);
    } // end of while statement
} //end of if statement

$conn->close();
echo json_encode(array($pairs));

When I attempt to get the data into my ajax/js I get an error. My JS is:

$("#getRecords").live('click', function() {
    var ajaxDataRenderer = function(url, plot, options) {
        var ret = null;
        $.ajax({
            type: "POST",
            async: false,
            url: url,
            dataType:"json",
            data: ({shelvDate: $('#shelvDate').val()}),
            success: function(data) {
                for(var x=0; x<data.first_name.length; x++) {
                    var info = [data.first_name[x], data.qty[x]];
                    ret.push(info);
                }
        }); // end of ajax call

        return ret;
    }; // end of ajaxDataRenerer call

    // The url for our json data
    var jsonurl = "shelvChart.php";
    var plot2 = $.jqplot('shelvChart', jsonurl,{
    seriesDefaults: {
           // Make this a pie chart.
           renderer: jQuery.jqplot.PieRenderer,
           rendererOptions: {
               // Put data labels on the pie slices.
               // By default, labels show the percentage of the slice.
               showDataLabels: true
           }
        }, 
        title: "Books Shelved",
        dataRenderer: ajaxDataRenderer,
        dataRendererOptions: {
            unusedOptionalUrl: jsonurl
        }
    });
});

I am don’t know what I’m doing wrong or even where to go from here as I am still new to AJAX and JS. Any help will be greatly appreciated.
Jim

  • 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-04T10:13:40+00:00Added an answer on June 4, 2026 at 10:13 am

    It would be very useful to see a real JSON string you are getting, cause I am not sure how you can get name[object,object],qty[object,object] after calling alert(ret) or maybe you are referring to other alert?.

    Anyway from what you are saying your problem is that you must make sure that the array returned by the ajaxDataRenderer function is of a proper format that is accepted by a pie chart.

    Therefore, for example, inside your PHP or JavaScript code you need to make sure that the returned array ret is of the following format:

    ret = [[name[0], qty[0]], [name[1], qty[1]], ...]; 
    

    This way all values that are in name array will be used as labels and qty array will be used as values from which the percentage will be evaluated.

    Similar approach that shows how to prepare data for a chart is shown in this answer.

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

Sidebar

Related Questions

I'm attempting to make the switch from Windows to ubuntu (am using 12.04 LTS)
I'm attempting to make a php script that can load the current weather forecast
I'm attempting to make a function in PHP that will evaluate a mathematical expression
Attempting to make a NSObject called 'Person' that will hold the login details for
Im attempting to make a little app that lets you add text boxes to
I'm attempting to make a custom ContentProvider so that more than one application (activity?)
I am attempting to make a program that will pull data such as OS,
I'm attempting to make a PDF from a HTML document, and this document has
I am attempting to make a simple class that serializes itself to disk when
I'm attempting to make a messaging system in which any class derived from Messageable

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.