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 6574607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:16:56+00:00 2026-05-25T15:16:56+00:00

Im trying to using Google Area Chart and PHP to display some data. problem

  • 0

Im trying to using Google Area Chart and PHP to display some data. problem is i just cant get it to work. if anyone can help it will be most appriciated.

Here is my code:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Date');
        data.addColumn('number', 'hits');
        data.addRows([
        <?php
$query = mysql_query("SELECT * FROM hits WHERE url='$url' GROUP BY date");
 while ($row = mysql_fetch_array($query)){
$hits=mysql_num_rows($query);
$date=$row['date'];?>
 ['<?php echo "$date";?>', <?php echo ".$hits.";?>],
<?php } ?>
]);

        var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
        chart.draw(data, {width: 400, height: 240, title: 'Company Performance',
                          hAxis: {title: 'Date', titleTextStyle: {color: '#FF0000'}}
                         });
      }
    </script>

    <div id="chart_div"></div>
  • 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-05-25T15:16:57+00:00Added an answer on May 25, 2026 at 3:16 pm

    I would definitely suggest separating your PHP (server side) code from your JavaScript/html (client side) code.

    The nice thing about the Google chart and graph APIs is there are several examples one can draw from, but it becomes much harder to reproduce something you’re viewing when you embed PHP with MySQL queries within the blocks that contain your JavaScript and UI elements.

    The following is a rough example of how you “might” go about dividing these things. In reality you would want your server side code (PHP in your case) in a totally separate file from your display/user interface code (HTML and JavaScript).

    The ‘DATE’ and ‘HITS’ in the “Front end code” block are not actually variables or values, I’m simply indicating this is where you would input your values. Ideally you would pass the data from your MySQL query through the PHP server code to the JavaScript code, and then iterate through it there to build your graph. The passing things back and forth from PHP to JS can be done nicely using the JSON data interchange format. Both PHP and JavaScript (jQuery) have functions for encoding and decoding to/from JSON.

    Front End Code:

    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Date');
        data.addColumn('number', 'hits');
        data.addRows(
           ['DATE', 'HITS']
        );
    
        var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
        chart.draw(data, {width: 400, height: 240, title: 'Company Performance',
                          hAxis: {title: 'Date', titleTextStyle: {color: '#FF0000'}}
                         });
      }
    </script>
    
    <div id="chart_div"></div>
    

    Back End Code:

    <?php
    $query = mysql_query("SELECT * FROM hits WHERE url='$url' GROUP BY date");
    $data_to_return = array();
    while ($row = mysql_fetch_array($query))
    {
        $hits=mysql_num_rows($query);
        $date=$row['date'];
        $data_to_return[$date] = $hits; //building array of date=>hits data
    }
    $data_to_send_to_front_end = json_encode($data_to_return); //ridiculous variable name
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to display some data points using google graphs, but unfortunately there is
I just started working using Google Maps API yesterday, and trying to set up
I'm trying to call a php webservice using WCF. I googled some public php
I'm trying to teach myself python using Google's AppEngine , and I can't get
I'm trying to extract some extra information from a location using google map api.
I'm trying to get the highlight/hover/mouseover styles working for a KMZ Placemark using Google
We are trying a prototype using Google chart api. http://chart.apis.google.com/chart?chf=bg,s,000000&chxs=0,FFFFFF00,9.5&chxt=x&chs=500x300&cht=p3&chco=3072F3|FF9900|80C65A|990066&chd=t:50,5,5,40&chdl=50%C2%B0%20Apples|5%C2%B0%20Oranges|5%C2%B0%20Dates|40%C2%B0%20Strawberries&chdlp=b&chp=0.1 the problem is when
I'm trying to parse some JSON data from the Google AJAX Search API. I
I am trying to fetch URLs using Google App Engine's urlFetch service and implement
I'm building a simple appliacation using the Google Maps API and I'm trying to

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.