[英]Creating data for Google pie chart
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. 我正在使用Google饼图( https://developers.google.com/chart/interactive/docs/gallery/piechart )显示我的数据。
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. 数据是从Wordpress收集的-只是在统计有多少公司是学术,商业或临床公司。 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? 对于输出数字1、2和1的测试数据,只需将变量放入代码中就可以创建微小的切片,如何填充饼图?
The pie in the google example adds up to 24 so what would be the equation? 谷歌示例中的馅饼加起来等于24,那么等式是什么? Ps 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);
}
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?"});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.