我有这个。
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;
},
}]
});
我需要在“afterLayout”键之后添加第二个功能。
更多信息请点击:https://www.chartjs.org/docs/latest/developers/plugins.html
最佳答案
定义并调用在调用 afterLayout 处理程序时要运行的两个函数:
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) {
....
};
然后在匿名函数中,您可以调用上面的两个。
type: 'line',
data: data,
options: options,
plugins: [{
id: "responsiveGradient",
afterLayout: function(downChart) {
func1(downChart);
func2(downChart);
},
}]
});
关于javascript - 如何向 Chartjs 中的插件添加第二个函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59127587/