Javascript chart.js plugins.register函数与外部数据
如何将数据传递到chart.plugins.register函数?我需要使用一些外部数据,但我不能,因为它缺少上下文:Javascript chart.js plugins.register函数与外部数据,javascript,angular,typescript,chart.js,Javascript,Angular,Typescript,Chart.js,如何将数据传递到chart.plugins.register函数?我需要使用一些外部数据,但我不能,因为它缺少上下文: Chart.plugins.register( { beforeDraw: function (chart) { //code } }); 我尝试了.bind(data),但它给出了错误。鉴于您的全局变量是Chart,您需要在组件中声明它 在导入下,在组件装饰器之前,执行以下操作 declare var Chart: any; 这样,您就可以访问全局变量 也
Chart.plugins.register( {
beforeDraw: function (chart) {
//code
}
});
我尝试了
.bind(data)
,但它给出了错误。鉴于您的全局变量是Chart
,您需要在组件中声明它
在导入下,在组件装饰器之前,执行以下操作
declare var Chart: any;
这样,您就可以访问全局变量 也许我的问题有误导性,我需要访问构造函数变量,比如
publicdata:data
是的,我不清楚。。。现在还不是。您想将数据传递到寄存器
,并且您有权访问它吗?是什么阻止了你?是的,我可以访问数据,但当我尝试执行Chart.plugins.register.bind(this.data)
时,它会给我错误,无法读取未定义的属性“indexOf”
所以我要求另一种方法