如何在php中创建图表时将数组传递给chart.js数据:[]

时间:2016-03-08 07:41:07

标签: javascript php arrays chart.js

我有这个数组$ data_dispensed,当我print_r()时,我得到了

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,',')?>]

它显示条形图,但悬停选项不再起作用,如何解决这个问题,当我对变量进行硬编码并悬停时,列实际显示数据

1 个答案:

答案 0 :(得分:1)

试试这段代码..

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