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

Fill colour derived/contextual to value (Radial Bar) #568

Closed
oller opened this issue May 3, 2019 · 3 comments
Closed

Fill colour derived/contextual to value (Radial Bar) #568

oller opened this issue May 3, 2019 · 3 comments

Comments

@oller
Copy link

oller commented May 3, 2019

Apologies if this is already possible, in which case an explanation would be appreciated and perhaps the docs (or myself) might be missing something!

Is your feature request related to a problem? Please describe.
Say I've a radial bar that I'd like the fill colour to go green if value is greater than 75%, or red if less than 25%. Or perhaps even the fill colour derived by the value, so a different colour for each percentage.

This is of course different to a gradient fill as i'm referring to a single fill colour.

Describe the solution you'd like
To support a fill function that takes the value as a param and can return a colour.

Describe alternatives you've considered
I've tried the updateOptions method to set a fill colour with a derived value, this works, but seems to break the initialising fill animation.

Any suggestions appreciated. Really enjoying working with this lib!

@junedchhipa
Copy link
Contributor

Good suggestion.
I have implemented the idea and tested it roughly which works fine like below.
Screen Shot 2019-05-03 at 5 04 59 PM

The code to achieve it will be

            fill: {
                colors: [function({ value }) {
                    if(value < 55) {
                        return '#7E36AF'
                    } else if (value >= 55 && value < 80) {
                        return '#164666'
                    } else {
                        return '#D9534F'
                    }
                }],
            }

Note that the colors array still accepts an array of a function instead of just a function (Changing this would cause type issues, hence kept the same).

It will be released in 3.6.10

@simonbuehler
Copy link

hi,

is there a way to have the gradient function in the same way, so when having a green->red gradient and the value is 25% ther shouldn't be any red yet visible in the gradient, any idea?

@sneko
Copy link

sneko commented Jun 2, 2020

Hi @junedchhipa ,

As described in my new issue #1652 I'm not able to make your code working even if described in the documentation (it triggers an error).

Is it still something possible?

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

No branches or pull requests

4 participants