Highcharts从数组中设置xaxis值

时间:2017-02-20 13:15:30

标签: php arrays highcharts

我需要在Highcharts中从数组中设置一些Xaxis值。

print_r($monthName);

我有阵列:Array ( [0] => August [1] => September [2] => October [3] => November [4] => December [5] => January )

我的代码是:

<script>
$(function () {
var monthNameData = [];
    monthNameData.push({
        data: ['<?php echo join ($monthName, ',') ?>']
    });

    $('#iw').highcharts({
        chart: {
            ...
        xAxis: {
           categories: monthNameData[0].data
        },
        series: ...
    });
});

我的结果是:

enter image description here

谢谢

1 个答案:

答案 0 :(得分:0)

如下所示纠正

<强>要么

monthNameData.push({
    data: <?php echo json_encode($monthName); ?>
});  

monthNameData.push({
       data: [<?php echo "'".join($monthName, "','")."'"; ?>]
});