Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript和PHP中的动态饼图数据_Php_Javascript_D3.js_Dynamic Data_Pie Chart - Fatal编程技术网

Javascript和PHP中的动态饼图数据

Javascript和PHP中的动态饼图数据,php,javascript,d3.js,dynamic-data,pie-chart,Php,Javascript,D3.js,Dynamic Data,Pie Chart,以下代码表示将在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:

以下代码表示将在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>

var agg={label:'Aggressive',pct:[60,10,6,30,14,10]},
bal={label:'Balanced',pct:[24,7,2,18,13,36]},
mod={label:'mediate',pct:[12,4,2,10,11,61]},
inc={label:'Income',pct:[0,0,0,0100]},
我希望将pct值作为php变量,而不是像上面的代码那样固定。我该怎么做

我希望它是
var agg=

$data是php变量

我希望在以下地址找到答案:

上面这个问题的第二个答案是var-treeData和函数toTree,看起来和我想做的完全一样。但是,如何将这些代码和函数应用到饼图中呢

我想通过php变量或php数组或json编码使6个值的pct数组成为动态的

我不想像上面所看到的那样
pct:[60,10,6,30,14,10]
,而是将6个值中的每一个都作为一个php变量。比如:pct:[$r1,$r2,$r3,$r4,$r5,$r6]。我该怎么做

我正在使用的代码可以在


我可以使用循环或递归函数来填充饼图数据吗?

这不是一个PHP问题,即如何创建一个PHP对象,其结构将呈现为饼图库所需的格式?是的。我想是的。我很难做到这一点。这个问题有点模糊。您的问题到底在哪里?使用MySQL检索百分比,或者迭代结果并在PHP中创建类似的数据结构?