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?

3
  • 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? Commented Oct 1, 2012 at 3:10
  • Well yes. I guess so. I'm having trouble doing just that. Commented Oct 1, 2012 at 3: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? Commented Nov 14, 2012 at 7:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.