【发布时间】:2018-05-02 12:47:58
【问题描述】:
我想根据数据的值在折线图中分配 pointBackgroundColor。 我有这个数组(示例):
Array ( [0] => 7 [1] => 2 [2] => 5 [3] => 6 [4] => 5 [5] => 6 [6] => 7 [7] => 5 [8] => 6 [9] => 4 [10] => 1 [11] => 2 [12] => 7 [13] => 1 [14] => 2 [15] => 1 [16] => 2 )
我将 intColors 初始化为一个颜色数组。
我已将构建图表的参数放入 $arrDataSets。
我现在需要知道如何根据条件定义颜色
例如如果 value > 2 那么 pointBackgroundColor = green ?
$intColors = array("#82f827", "#ff4040", "#31698A", "#6666FF","#ff7F50","#fe6b60","#6c1ba1","#97bdd6");
foreach($datasetR1 as $value){
}
$arrDatasets = array(
array('label' => "event_name",
'fill' => false,
'showLine' => false,
'pointBackgroundColor' => $intColors,
'data' => $datasetR1
));
$arrReturn = (array('labels' => $labels,
'datasets' => $arrDatasets));
$mydata = json_encode(($arrReturn));
【问题讨论】:
标签: php arrays loops chart.js linechart