Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    99
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Creating pie chart by taking values from the database

    Hi,

    i want to create a pie chart in my website by taking values from database. I should display the top 10 most purchased product in the form of pie chart in my website. But i dont know how to do it. I have no clue how to start.

    Please someone help me in this.

  • #2
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    339
    Thanks
    63
    Thanked 11 Times in 11 Posts
    Hi. I think your best bet would be to have a look at the Google Chart API, should be able to do this for you.

    https://developers.google.com/chart/

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Google chart is a good one, and there are a LARGE number of free softwares you can pick up, some straight PHP, others PHP/JS, others PHP/Flash.

  • #4
    New Coder
    Join Date
    Jan 2011
    Posts
    99
    Thanks
    8
    Thanked 0 Times in 0 Posts
    But i dont know how to use google API and please send me the link for other softwares please.

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    10 seconds of googling either of those gets you the results you want. Google charts is well documented and very easy to use.

  • #6
    New Coder
    Join Date
    Jan 2011
    Posts
    99
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Hey,

    Here is my code. I tried doing like this , but nothing is getting displayed. blank screen displays. I don't know where i am going wrong. Please help me


    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 = google.visualization.arrayToDataTable([
              ['Task', 'Hours per Day'],
              <?php 
    		  $stringResult;
              $i = 0;
    		  $sql = "select * from product inner join product_description on product.product_id = product_description.product_id order by product.viewed desc limit 10";
    		  $results1 = $this->db->query($sql);
    		  //for($i=0; $i<10; ++$i)
    		  {
    		  $stringResult .= "data[" .$i. "] = { label:" .$results['name'].", data: ". $results['quantity'] ."}";
    		   $i++;
              //start loop
              //while or foreach
             // foreach($data as $v){
               // echo ",['{$name}'],{$count}]\r\n";
    			return $stringResult;
              }
              ?>
            ]);
    
            var options = {
              title: 'My Daily Activities'
            };
    
            var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
            chart.draw(data, options);
          }
        </script>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •