3

The following code represent the data that will be shown in a pie chart visualization in javascript.

<script type="text/javascript">

    var agg = { label: 'Aggressive', pct: [60, 10, 6, 30, 14, 10] },
        bal = { label: 'Balanced',   pct: [24,  7, 2, 18, 13, 36] },
        mod = { label: 'Moderate',   pct: [12,  4, 2, 10, 11, 61] },
        inc = { label: 'Income',     pct: [ 0,  0, 0,  0,  0,100] },

</script>

I would like to have the pct values as php variables, and not fixed as in the code above. How do I do this?

I would like to have it as var agg = <?php echo json_encode($data); ?>;

$data being the php variable

I would like to have it as in the answer found at: Dynamic Javascript Tree Structure

The second answer to the above linked question with the var treeData and function toTree, seems exactly like what I want to do. But,how do I apply that code and functions to my pie chart?

I would like to make the pct array of 6 values dynamic through a php variable or php array or json encode.

Instead of pct: [60, 10, 6, 30, 14, 10] as seen above, I would like to ake each of 6 values a php variable. Like: pct: [$r1, $r2, $r3, $r4, $r5, $r6] . How do I do this?

The code that I am working with can be found at http://jsfiddle.net/MX7JC/9/

Can I use a loop or recursive function to populate the pie chart data?

Community
  • 1
  • 1
user1704514
  • 227
  • 3
  • 4
  • 12
  • Wouldn't this be more of a PHP question, namely how to create a PHP object with a structure that will be rendered to the format required by the pie chart library? – BobS Oct 01 '12 at 03:10
  • Well yes. I guess so. I'm having trouble doing just that. – user1704514 Oct 01 '12 at 03:17
  • the question is somewhat vague. Where exactly lies your problem - in retrieving the percentage with MySQL or iterating through the result and creating a similar data structure in PHP? – Matanya Nov 14 '12 at 07:21

0 Answers0