2017-02-20 79 views
1

我需要在Highcharts中從數組中設置一些Xaxis值。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

謝謝

回答

0

正確像下面

要麼

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

OR

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

非常感謝你。它正在工作。 –