[英]How do I add a second function to a plugin in chartjs?
我有這個。
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);
},
}]
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.