ArielMejiaDev / larapex-charts

A Laravel wrapper for apex charts
https://larapex-charts.netlify.app/
MIT License
284 stars 84 forks source link

Feature request:add random color to setColors #90

Closed saeedvir closed 7 months ago

saeedvir commented 8 months ago

add random colors or shuffle colors in config file

public function setColors(array $colors) :LarapexChart

marineusde commented 7 months ago

You can do it for yourself with a simple class:

class RandomColor
{
    public static function getRandomColors(int $count): array
    {
        $array = [];
        for ($i = 1; $i <= $count; $i++) {
            $array[] = self::getRandomColor();
        }

        return $array;
    }

    private static function getRandomColor(): string
    {
        $color = '#';
        for ($i = 1; $i <= 6; $i++) {
            $color .= self::getRandomColorElement();
        }

        return $color;
    }

    private static function getRandomColorElement(): string
    {
        $colors = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];

        return $colors[array_rand($colors)];
    }
}

Then use it:

->setColors(RandomColor::getRandomColors(5))
ArielMejiaDev commented 7 months ago

As setColors() allows to add your custom array in any order, I think this is out of the scope for the package.