...

View Full Version : Creating pie chart by taking values from the database



Mythri
07-11-2012, 01:45 PM
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.

paddyfields
07-11-2012, 03:28 PM
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/

Keleth
07-11-2012, 03:48 PM
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.

Mythri
07-11-2012, 06:38 PM
But i dont know how to use google API and please send me the link for other softwares please.

Keleth
07-11-2012, 06:59 PM
10 seconds of googling either of those gets you the results you want. Google charts is well documented and very easy to use.

Mythri
07-12-2012, 05:15 AM
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



<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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum