Reputation: 6380
I guess this maybe more of a maths question but I'll try anyway! I'm using a Google pie chart (https://developers.google.com/chart/interactive/docs/gallery/piechart) to display my data.
How can I create a full pie chart, at the moment it's just creating tiny slices that don't fill the whole pie!
The data is gathered from Wordpress - it's just counting how many companies are either academic, business or clinical. These are variables like the following:
<p>Academic<?php echo $academic;?></p>
<p>Business<?php echo $business;?></p>
<p>Clinical<?php echo $clinical;?></p>
For my test data that has output the numbers 1, 2 and 1. By just putting the variables into the code it creates tiny slices, how can I fill the pie?
The pie in the google example adds up to 24 so what would be the equation? P.s I'm rubbish at maths!
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawVisualization);
function drawVisualization() {
// Create and populate the data table.
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Academic', '<?php echo $academic; ?>'],
['Business', '<?php echo $business; ?>'],
['Clinical', '<?php echo $clinical; ?>']
]);
var options = {
backgroundColor: 'none',
chartArea: {width:"221",height:"221"},
width:'221',
height:'221',
legend: {position: 'none'},
tooltip: {trigger: 'none'},
enableInteractivity: false,
slices: {0: {color: '#a95892'}, 1:{color: '#d7663a'}, 2:{color: '#316086'}}
};
// Create and draw the visualization.
new google.visualization.PieChart(document.getElementById('chart_div')).
draw(data, options);
}
Upvotes: 1
Views: 2137
Reputation: 898
This should work (at least it does for me in the Code Playground):
function drawVisualization() {
var data = google.visualization.arrayToDataTable([
['Type', 'Amount'],
['Academic', <?php echo $academic;?>],
['Business', <?php echo $business;?>],
['Clinical', <?php echo $clinical;?>]]);
new google.visualization.PieChart(document.getElementById('visualization')).draw(data, {title:"how many?"});
}
Upvotes: 2