我猜这可能更像是一个数学问题,但我还是要试试!我使用Google饼状图(https://developers.google.com/chart/interactive/docs/gallery/piechart)来显示我的数据。
我怎么能创建一个完整的饼状图,目前它只是创建微小的切片,不能填满整个饼!
数据是从Wordpress收集的——它只是计算有多少公司是学术的,商业的或临床的。这些变量如下所示:
<p>Academic<?php echo $academic;?></p>
<p>Business<?php echo $business;?></p>
<p>Clinical<?php echo $clinical;?></p>
对于我的测试数据,输出数字1,2和1。通过将变量放入代码中,它创建了小块,我如何填充饼呢?
这个饼在谷歌的例子中加起来是24,那么方程是什么呢?附言:我数学很烂!
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);
}
这应该可以工作(至少在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