Dynamic Pie Chart Data in Javascript and PHP

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] },


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

  • How can I add a click event to show a tooltip in an NVD3 Pie Chart?
  • How to get coordinates of slices along the edge of a pie chart?
  • Adding new nodes to Force-directed layout
  • Datejs and d3.js conflict with transition
  • Can d3.js draw two scatterplots on the same graph using data from the same source?
  • Compare/Diff new data with previous data on d3.js update
  • 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?

  • Unusual d3 zoom in reusable class - this and bind
  • How can I add the fisheye lens effect to my hierarchical edge bundling graph?
  • Append DOM element to the D3
  • What does D3's “empty” selection do?
  • Unable to filter using html input value in D3JS
  • How to organise/nest data for d3.js chart output