Skip to content
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

Percentage Color Changes? #91

Open
stev310 opened this issue Apr 14, 2014 · 2 comments
Open

Percentage Color Changes? #91

stev310 opened this issue Apr 14, 2014 · 2 comments
Labels

Comments

@stev310
Copy link

stev310 commented Apr 14, 2014

How can I associate percentages to different colors? For barcolor in your key it says:

"But you can also pass a function that accepts the current percentage as a value to return a dynamically generated color."

Can you please give me some steps to do this? I'd like it to transition from Green 0-40, Yellow 40-85, Red from 85-100.

Thank you!!

@thelarz
Copy link

thelarz commented Apr 15, 2014

Here's how I've solved a similar problem. You can simplify for your needs.

FYI, This is an angular function, but it would work the same in vanilla js.

$scope.barColor = function () {

    var score = parseInt($scope.tile.Rank, 10);
    var target = parseInt($scope.tile.GoalValue, 10);

    if (target === null) {
        target = 50;
    }

    var color = "";

    if (score < (target - (target * 0.2)))
        color = "#ee1010";
    else if (score < target)
        color = "#e6c908";
    else {
        color = "#74b818";
    }
    if (score === 0) {
        color = "#666666";
    }

    return color;

};

@mrzmyr mrzmyr added the question label May 6, 2014
@thornyeternity
Copy link

I removed:
var color;
if (typeof(options.barColor) === 'function') {
color = options.barColor(percent);
} else {
color = options.barColor;
}
in the JQuery file and replaced it with:

if(percent >= 90){
color = '#5ebe01'; //green
}else if(percent <= 89 && percent >= 51){
color = '#fe7903';//orange
}else if(percent <= 50){
color = '#ed2e08'; //red
}

which worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants