2016-03-08 93 views
-1

創建圖表我有這個數組$ data_dispensed,當我print_r()它,我得到如何通過一個數組chart.js之數據:[],而在PHP

Array (
    [0] => 270.00 
    [1] => 22956.00 
    [2] => 23655.00 
    [3] => 27418.00 
    [4] => 2295820.50 
    [5] => 114476.00 
    [6] => 312220.00 
    [7] => 26580.00 
    [8] => 12680.00 
    [9] => 6300.00 
) 

它是沒

現在,當我的數組傳遞給data:[]chart.js


data: [<?php echo join($data_dispensed,',')?>] 

它顯示的條形圖,但懸停選擇不工作了,我怎麼能解決這個問題,當我硬編碼的變量和懸停,列實際顯示的數據

+0

是否有一個原因,你不是用JS存儲數據,而不是通過PHP回數組到JS數組? – user3821538

+0

您是否嘗試過使用'json_encode'來轉換數組? – Quince

回答

1

試試這個代碼..

data: [<?php $s2 = array(); 
foreach ($data_dispensed as $value) 
$s2[] = round($value); 
echo implode(',',$s2); ?>]