duan0714 2014-04-10 22:19
浏览 25
已采纳

PHP var的Highcharts

I am novice with JavaScript, and in my website I need to use highchart with some PHP var. And I have a question : With Highchart, I need to complete some information :

xAxis: {
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},

I have my array in PHP coverted in JavaScript with :

var array = <?php echo json_encode($array); ?>;

But, the length of my array is never the same length between differents users. And I need to complete "categories" with all the values in my array.

How can I do this?

  • 写回答

2条回答 默认 最新

  • dougong5817 2014-04-11 20:05
    关注

    My actual code is the following :

    xAxis: {
        categories: [<?php foreach($array as $value) {
            echo "'".$value."', ";
        }?>]
    },
    

    But it doesn't work, because the graph don't appear. :/

    EDIT : Solution is :

    var array = <?php echo json_encode($array); ?>;
    

    And then

    xAxis: {
        categories: array 
    },
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?