Gradient not applied
See original GitHub issueI’m trying to apply a gradient as background color to labels but it doesn’t work.
Here is code, based on data labels sample:
<script id="script-init">
var ctx = document.getElementById('chart-0').getContext("2d");
var gradientStroke = ctx.createLinearGradient(500, 0, 100, 0);
gradientStroke.addColorStop(0, "#80b6f4");
gradientStroke.addColorStop(1, "#f49080");
var DATA_COUNT = 8;
var labels = [];
Samples.srand(8);
for (var i = 0; i < DATA_COUNT; ++i) {
labels.push('' + i);
}
Chart.helpers.merge(Chart.defaults.global, {
aspectRatio: 4/3,
tooltips: false,
layout: {
padding: {
top: 42,
right: 16,
bottom: 32,
left: 8
}
},
elements: {
line: {
fill: false
}
},
plugins: {
legend: false,
title: false
}
});
</script>
<script id="script-construct">
var chart = new Chart('chart-0', {
type: 'line',
data: {
labels: labels,
datasets: [{
backgroundColor: gradientStroke,
borderColor: gradientStroke,
data: Samples.numbers({
count: DATA_COUNT,
min: 0,
max: 100
})
}]
},
options: {
plugins: {
datalabels: {
backgroundColor: function(context) {
return gradientStroke;
},
borderRadius: 4,
color: 'white',
font: {
weight: 'bold'
},
formatter: Math.round
}
},
scales: {
yAxes: [{
stacked: true
}]
}
}
});
</script>
Here is the result:
There is a similar issue in Chart.js, fixed in the master .
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
linear-gradient not working in Chrome - Stack Overflow
After a good amount of search I am stuck with linear-gradient which works in Firefox but not in Chrome.
Read more >Background Gradient Not Working - HTML & CSS - SitePoint
I have been trying to add some gradient to the body of my template and after a couple of goes it still does...
Read more >linear-gradient() - CSS: Cascading Style Sheets | MDN
The linear-gradient() CSS function creates an image consisting of a progressive transition between two or more colors along a straight line.
Read more >Solved: illustrator gradient tool not working? - 8570511
If you select another object and the gradient annotator disappears, then that item is filled with a solid color and not a gradient....
Read more >Gradient not working in Safari - Support - Themeco Forum
I have a layout page that is using some CSS gradient overlays. ... The gradients show fine on Chrome but in Safari they...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @stockiNail for the extra details about the context, it looks really great.
In the meantime, here is a “non ideal” workaround if you use (or want to use) a color lib such as chroma, etc., you could interpolate the background color using scriptable options (jsfiddle).