以下代码用于在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>
而不是如上所述的tm: [40, 60, 67, 30, 74, 50]
,我想使6个值中的每一个都成为php变量。喜欢:tm: [$r1, $r2, $r3, $r4, $r5, $r6]
。我该怎么做?
我该怎么做? php数组或json编码?
答案 0 :(得分:2)
是的,json_encode
一个PHP数组:
var agg = <?php echo json_encode(array('label' => 'Aggressive', 'pct' => array($r1, $r2, ...))); ?>,
bal = <?php echo json_encode(...); ?>,
...