I have this.
type: 'line',
data: data,
options: options,
plugins: [{
id: "responsiveGradient",
afterLayout: function(downChart) {
console.log(downChart);
let scales = downChart.scales;
let color = downChart.ctx.createLinearGradient(0, scales["x-axis-0"].top, 0, 0);
//let chartColors = getChartColors(status);
color.addColorStop(0, "rgba(0, 181, 63, 0.01)");
color.addColorStop(1, "rgba(0, 181, 63, 0.6)");
downChart.data.datasets[0].backgroundColor = color;
},
}]
});
And i need to add a second function after the "afterLayout" key.
More information here: https://www.chartjs.org/docs/latest/developers/plugins.html
Define and call the two functions you want to run when the afterLayout handler is called:
function func1(downChart) {
console.log(downChart);
let scales = downChart.scales;
let color = downChart.ctx.createLinearGradient(0, scales["x-axis-0"].top, 0, 0);
//let chartColors = getChartColors(status);
color.addColorStop(0, "rgba(0, 181, 63, 0.01)");
color.addColorStop(1, "rgba(0, 181, 63, 0.6)");
downChart.data.datasets[0].backgroundColor = color;
};
function func2(downChart) {
....
};
Then within the anonymous function, you can call the two above.
type: 'line',
data: data,
options: options,
plugins: [{
id: "responsiveGradient",
afterLayout: function(downChart) {
func1(downChart);
func2(downChart);
},
}]
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.