1

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); } 

1 Answer 1

2

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?"}); } 

http://h3n.info/pie.png

Sign up to request clarification or add additional context in comments.

5 Comments

All that's done from the google example is change "hours per day" to "Amount"... it still will only plot small segments, not fill the whole pie.
but it does in the Code Playground (code.google.com/apis/ajax/playground/…)
Maybe you have additional code that changes the default behaviour of the pie chart, paste your full code please. This is how it looks like in my browser: h3n.info/pie.png
Just pasted my code. Hmm, it works in the playground but not on my site - it just shows the small segments.
You wrote '<?php echo $academic;?>' which generates '2' which is a string and not the expected integer value. try removing the apostrophes (').

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.