I’m putting together a pie chart using JQPlot being fed via JSON from a MySQL table and am trying to see if there are any gurus out there who might be able to answer a question for me. I have the pie chart working as it’s supposed to in that it takes an array, divided it up by percentage of the total amount, and displays the chart. From here, is it possible to feed in another value to become the pie’s total value, subtract the total value of the array from that, and show the array items’ percentages in relation to the entire pie?
For example, if I give JQPlot this array, [[a,2],[b,4],[c,2]], it would output a chart that shows a=25%, b=50%, c=25% of the total pie. I want to give it another value of 10 to represent the entire pie thus forcing that array to output a=20%, b=40%, c=20% with an extra 20% left over.
The code I’m starting with is the basic pie chart example from the JQPlot site, and my desired total pie value is set up to be fed in from getGrossTotal.php. If it can’t be done, it can’t be done. I just want to check around for ideas as to how to handle it.
$(document).ready(function(){
$.getJSON('getGrossTop.php', function(grossTop){
var plot1 = jQuery.jqplot ('pieChart', [grossTop],{
seriesDefaults: {
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
showDataLabels: true
}
},
legend: {
show:true,
location: 'e'
},
});
});
});
Thanks!
Nevermind. Instead of trying to handle the extra number in javascript, I went back to the PHP side, totaled the values of each minor array, subtracted that result from the sum of everything in the database, and pushed that result into the major array to encode. It basically made an additional minor array item with a label of nothing and value of the number I wanted. When I passed all that into JQPlot, it gave me what I was looking for. Thanks for all who took a look.