I have a rather simple 3D pie chart where I read the labels and values from a database query and dump them into an array; this is working fine if I use a set number of results - ie, a top 10 query, etc. For example, the code below I list the top 9 call drivers, and group the remaining values into an "Other" category - so there are always 10 slices to the pie.
What I would like to do is do a loop or somehow allow the chart to draw for an unknown number of elements... for example, a pie chart on users where users change frequently - so one week there may be 7 slices total, the next week 11, then 8, etc.
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
[' Call Drivers', 'Count'],
['<% =CallDriverArray(0,0) %>', <% =CallDriverArray(0,2) %>],
['<% =CallDriverArray(1,0) %>', <% =CallDriverArray(1,2) %>],
['<% =CallDriverArray(2,0) %>', <% =CallDriverArray(2,2) %>],
['<% =CallDriverArray(3,0) %>', <% =CallDriverArray(3,2) %>],
['<% =CallDriverArray(4,0) %>', <% =CallDriverArray(4,2) %>],
['<% =CallDriverArray(5,0) %>', <% =CallDriverArray(5,2) %>],
['<% =CallDriverArray(6,0) %>', <% =CallDriverArray(6,2) %>],
['<% =CallDriverArray(7,0) %>', <% =CallDriverArray(7,2) %>],
['<% =CallDriverArray(8,0) %>', <% =CallDriverArray(8,2) %>],
['Other', <% =otherTotal %>]
]);
var options = {
title: '',
hAxis: {title: '', titleTextStyle: {color: 'red'}},
fontSize: '11',
is3D: true,
chartArea:{left:10,top:10,width:"95%",height:"90%"},
backgroundColor: '#F8F8F8'
};
var chart = new google.visualization.PieChart(document.getElementById('call_driver'));
chart.draw(data, options);
}
</script>