Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript chart.js plugins.register函数与外部数据_Javascript_Angular_Typescript_Chart.js - Fatal编程技术网

Javascript chart.js 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函数?我需要使用一些外部数据,但我不能,因为它缺少上下文:

Chart.plugins.register( {
  beforeDraw: function (chart) {
    //code
  }
});

我尝试了
.bind(data)
,但它给出了错误。

鉴于您的全局变量是
Chart
,您需要在组件中声明它

在导入下,在组件装饰器之前,执行以下操作

declare var Chart: any;

这样,您就可以访问全局变量

也许我的问题有误导性,我需要访问构造函数变量,比如
publicdata:data
是的,我不清楚。。。现在还不是。您想将数据传递到
寄存器
,并且您有权访问它吗?是什么阻止了你?是的,我可以访问数据,但当我尝试执行
Chart.plugins.register.bind(this.data)
时,它会给我错误,
无法读取未定义的属性“indexOf”
所以我要求另一种方法