Closed mhnayeb closed 1 year ago
@mhnayeb I think the fill option in line dataset is missing and default is false. Try adding fill: true
to dataset configuration
Thanks for your fast response. I added the fill: true
option inside datasets
object and it wont work. I just followed the official documents on chartjs
website and this repo but nothing worked!
new config:
datasets: [{
fill: true,
backgroundColor: '#f87979',
data: [40, 39, 10, 40, 39, 80, 40],
gradient: {
backgroundColor: {
axis: 'y',
colors: {
0: 'red',
50: 'red',
100: 'red'
}
},
borderColor: {
axis: 'x',
colors: {
0: 'purple',
1: 'red',
2: 'purple',
3: 'red'
}
}
}
}]
Can you provide a reproducible sample? I have created a codepen and is working: https://codepen.io/stockinail/pen/ZEoKqVa
It easier for me to recreate it in codesandbox
I replicated that exact problem there! here is the link: https://codesandbox.io/s/chartjs-background-gradient-ujmkv0?file=/src/components/lineChart.ts
it works great outside of vue.js environment or in your example! it only break inside of vue.js environment
Found it.
The fill of the area is based on filler plugin is not included and register in your sample (I didn't recognize it reading your code).
import {
Chart as ChartJS,
Title,
Tooltip,
Legend,
LineElement,
LinearScale,
PointElement,
CategoryScale,
Plugin,
Filler // <--MUST be added
} from "chart.js";
ChartJS.register(
Title,
Tooltip,
Legend,
LineElement,
LinearScale,
PointElement,
CategoryScale,
gradient,
Filler // <--MUST be added
);
I filed an issue to the Chart.js repo about this: https://github.com/chartjs/Chart.js/issues/10700
Hey there I was looking around and founded your great plugin! but it only work on border and it wont fill under the line chart as expected! Here is my sample and these are my dependencies I use:
PS: I'd be happy to help you fix the bug!