Search code examples
pchart

pChart Bar Charts set color depending on threshold


Good Day To All I'm new to pCharts, works great! I'm trying to create a bar chart with 2 thresholds and display different bar colors. Setting the thresholds is done and works well. Now I would like to set the standard palette to a set color and only the bars that exceed the specified second threshold should be a different color. My data consists of times file were imported So in theory, if possible, all bars exceeding the 2nd limit should be red or pink or whatever. Is this possible? If so, where do I start fiddling? I have tried OverideColors with an if statement but it seems not to work so well. Any info would be very helpful. Thanks


Solution

  • Ok, so here is the code. I know there might be better or cleaner ways of doing it but this works:

    /*Palette per Bar*/
     $thold = strtotime("09:30:00");
      foreach ($lastdate as $over) {
        if ($over < $thold) {
          $color = array("R"=>0,"G"=>204,"B"=>204);
          $Palette[] = $color;
        }
        else {
          $color2 = array("R"=>224,"G"=>46,"B"=>117);
          $Palette[] = $color2;
        }
       }
    

    Hope this helps