将数组传递给chart.js选项



我有这个数组:

array (
0 => 'rgba(202, 63, 20, 1)',
1 => 'rgba(35, 14, 225, 1)',
2 => 'rgba(73, 128, 13, 1)',
3 => 'rgba(238, 62, 10, 1)',
4 => 'rgba(85, 152, 95, 1)',
5 => 'rgba(57, 156, 150, 1)',
)

但我必须在chart.js图表中使用它作为参数,我需要这种格式:

['rgba(202, 63, 20, 1)', 'rgba(35, 14, 225, 1)', 'rgba(73, 128, 13, 1)']

我必须用PHP来做。一些想法?谢谢C.

我就是这样修复的:我用以下字符串将rgba数组传递给Chart.js中的"backgroundColor"选项:

backgroundColor: <?php echo json_encode($ColorArray); ?>,

现在它起作用了。

我的错误是将php变量直接传递给chart.js的backgroundColor选项,如下所示:

backgroundColor: $ColorArray,

最新更新