Dynamic Pie Chart Data in Javascript and PHP

人盡茶涼 提交于 2019-12-31 01:47:08

问题


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?

来源:https://stackoverflow.com/questions/12666888/dynamic-pie-chart-data-in-javascript-and-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!