0

I want to assign pointBackgroundColor in a line-chart depending on the value of the data. I have this array (example) :

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 )

I initialized intColors as an array of colors.
I have put into $arrDataSets the parameters to build the chart.
I now need to know how to define the colors depending on conditions
For example if value > 2 then 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));
rn605435
  • 175
  • 2
  • 12

1 Answers1

0
foreach($datasetR1 as $value){
                if($value == 1){
                    array_push($intColors, "#82f827");
                }
                elseif($value == 2){
                    array_push($intColors, "#ff4040");
                }
                elseif($value == 3){
                    array_push($intColors, "#31698A");
                }
                elseif($value == 4){
                    array_push($intColors, "#6666FF");
                }
                elseif($value == 5){
                    array_push($intColors, "#ff7F50");
                }
                elseif($value == 6){
                    array_push($intColors, "#fe6b60");
                }
                elseif($value == 7){
                    array_push($intColors, "#6c1ba1");
                }
                elseif($value == 8){
                    array_push($intColors, "#97bdd6");
                }
            }
rn605435
  • 175
  • 2
  • 12