Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request:add random color to setColors #90

Closed
saeedvir opened this issue Jan 7, 2024 · 2 comments
Closed

Feature request:add random color to setColors #90

saeedvir opened this issue Jan 7, 2024 · 2 comments

Comments

@saeedvir
Copy link

saeedvir commented Jan 7, 2024

add random colors or shuffle colors in config file

public function setColors(array $colors) :LarapexChart

@marineusde
Copy link
Contributor

marineusde commented Jan 31, 2024

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
Copy link
Owner

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

@ArielMejiaDev ArielMejiaDev reopened this Feb 8, 2024
Repository owner locked and limited conversation to collaborators Feb 8, 2024
@ArielMejiaDev ArielMejiaDev converted this issue into discussion #98 Feb 8, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants