-
Notifications
You must be signed in to change notification settings - Fork 38
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
Barchart: Error unable to parse color from object #10
Comments
Here is a workaround I got working by adjusting Chart.js (v2.4.0). These errors get thrown because the backgroundColor is not a standard color, but instead a CanvasPattern. I'm not sure how this would get fixed in this library instead of Chart.js, but regardless here's what I got working for me. The fix here is to detect when it's trying to use the CanvasPattern incorrectly and adjust it to use either the CanvasPattern that already exists or a solid color if that's what it's looking for. If you define
Then to adjust the tooltip, set drawBody on line ~13564 to the following (only ~5 lines have been edited and commented below which part is important):
This will use the existing CanvasPattern in the tooltip when backgroundColor is actually a pattern, and voila no more errors. |
I use this simple workaround (with pattornamaly & chart.js 2.5) const getPattern = (shape, color)=> {
let rgb = Chart.helpers.colors(color)
let bgPattern = pattern.draw(shape, color)
return Chart.helpers.extend(bgPattern, {r: rgb.red(), g: rgb.green(), b: rgb.blue(), alpha: rgb.alpha()})
}
// in my chart options
// ...code omitted.....
const backgroundColor = getPattern("dot", "red");
let chart = new Chart(ctx, {
data: {
labels: ['Item 1', 'Item 2', 'Item 3'],
datasets: [{
data: [10, 20, 30],
backgroundColor
}]
}
}) |
Hello,
I'm getting the following error when using patternomaly as the backgroundColor when using a barchart:
The error comes from the following code in the Chart.js library in /dist/Chart.js around line 280:
obj only has the shapeType property. Is this fixable? The error occurs when hovering over the chart.
The text was updated successfully, but these errors were encountered: