doulun1915 2012-10-01 03:34
浏览 43

用PHP变量数组填充javascript数组[重复]

Possible Duplicate:
Dynamic Pie Chart Data in Javascript and PHP

The following code is used to populate a pie chart 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>

Instead of tm: [40, 60, 67, 30, 74, 50] as seen above, I would like to make each of 6 values a php variable. Like: tm: [$r1, $r2, $r3, $r4, $r5, $r6] . How do I do this?

How do I do this with? A php array or json encode?

  • 写回答

1条回答 默认 最新

  • douke3335 2012-10-01 03:38
    关注

    Yes, json_encode a PHP array:

    var agg = <?php echo json_encode(array('label' => 'Aggressive', 'pct' => array($r1, $r2, ...))); ?>,
        bal = <?php echo json_encode(...); ?>,
        ...
    
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统