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

Make bar styling options scriptable #5780

Merged
merged 1 commit into from Nov 12, 2018

Conversation

simonbrunel
Copy link
Member

@simonbrunel simonbrunel commented Oct 21, 2018

The bar backgroundColor, borderColor, borderWidth and borderSkipped options are now scriptable (unit tests, docs and a basic sample). Also fix the gulp task that generates the documentation on Windows.

For example:

image

backgroundColor: function(ctx) {
    var v = ctx.dataset.data[ctx.dataIndex];
    var c = v < -50 ? '#D60000'
        : v < 0 ? '#F46300'
        : v < 50 ? '#0358B6'
        : '#44DE28';

    return Color(c).alpha(1 - Math.abs(v / 150)).rgbString();
}

borderColor: function(ctx) {
    var v = ctx.dataset.data[ctx.dataIndex];
    return v < -50 ? '#D60000'
        : v < 0 ? '#F46300'
        : v < 50 ? '#0358B6'
        : '#44DE28';
}

Fixes #5302

@simonbrunel
Copy link
Member Author

About the CodeClimate issue, I'm going to see how to refactor it when introducing scriptable options for the line chart, which is a bit different because of the inconsistent option naming between the dataset and the options.elements.

etimberg
etimberg previously approved these changes Oct 21, 2018
@chartjs chartjs deleted a comment from benmccann Oct 22, 2018
@chartjs chartjs deleted a comment from benmccann Oct 22, 2018
@chartjs chartjs deleted a comment from benmccann Oct 22, 2018
@chartjs chartjs deleted a comment from benmccann Oct 22, 2018
@chartjs chartjs deleted a comment from benmccann Oct 22, 2018
benmccann
benmccann previously approved these changes Oct 24, 2018
Copy link
Contributor

@benmccann benmccann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm. I think there's one unused variable, but otherwise feel free to merge

@simonbrunel simonbrunel dismissed stale reviews from benmccann and etimberg via dd33a8e October 24, 2018 07:45
etimberg
etimberg previously approved these changes Oct 24, 2018
The bar `backgroundColor`, `borderColor`, `borderWidth` and `borderSkipped` options are now scriptable (unit tests, docs and a basic sample). Also fix the gulp task that generates the documentation on Windows.
@simonbrunel
Copy link
Member Author

@benmccann @etimberg I merged this one because you previously approved it (I just rebased since and addressed @benmccann comment).

exwm pushed a commit to exwm/Chart.js that referenced this pull request Apr 30, 2021
The bar `backgroundColor`, `borderColor`, `borderWidth` and `borderSkipped` options are now scriptable (unit tests, docs and a basic sample). Also fix the gulp task that generates the documentation on Windows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bar chart color depending on the value.
3 participants