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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:35:29+00:00 2026-06-19T02:35:29+00:00

How do I populate the Google Chart API with my own Server side data

  • 0

How do I populate the Google Chart API with my own Server side data i.e. in PHPMySQL.

Currently I have the following data:

function drawChart()
{
 // Create the data table.
 var data = new google.visualization.DataTable();
 data.addColumn('string', 'City');
 data.addColumn('number', 'Number of Crimes');
 data.addRows([
             ['Cardiff', 300],
             ['London', 900],
             ['Manchester', 500],
             ['Dublin', 400],
             ['Liverpool', 600]
             ]);

// Set Chart Options
var options = {
    'legend': 'left',
    'title': 'Crimes (per day)',
    'is3D': 'True',
    'width':400,
    'height':300
};

// Instantiate and Draw Chart.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}

But how do I feed it the data from a table in my mySQL database?

  • 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-19T02:35:30+00:00Added an answer on June 19, 2026 at 2:35 am

    Before the JavaScript-Code of the Charts API you have to get your data out of your database:

    //Your database query goes here
    $list = mysql_query("SELECT city,crimes FROM TABLE");
    while($row = mysql_fetch_assoc($list)){
      $data[] = "['".$row['city']."', ".$row['crimes']."]";
    }
    $data_for_chart = implode(",\n"$data);
    

    Now replace in your JS-code:

    data.addRows([
             ['Cardiff', 300],
             ['London', 900],
             ['Manchester', 500],
             ['Dublin', 400],
             ['Liverpool', 600]
             ]);
    

    With:

    data.addRows([
             <?php echo $data_for_chart; ?>
             ]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to populate google chart datatable in server side using PHP.I got JSON
I have a Google Chart (using the Google Visualization API , not Google Charts
I am trying to use the Google Charts API to create a chart that
I am currently using Google Charts with PHP to populate the data but the
The following example is from Google to create a ColumnChart using Google Charts function
I have an app that uses a google spreadsheet to populate a menu and
I'm trying to use google visualization api in jboss seam 2 project. I have
I have an Android application and I'm trying to populate a Google Map with
I have a few questions regarding Google Chart Tools. Do we actually need a
I have a Google Chart's ColumnChart in a Rails project. This is generated and

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.