Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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
如何使用TypeScript将ChartPoint添加到Chart.js中的数据集?_Typescript_Chart.js_Powerbi - Fatal编程技术网

如何使用TypeScript将ChartPoint添加到Chart.js中的数据集?

如何使用TypeScript将ChartPoint添加到Chart.js中的数据集?,typescript,chart.js,powerbi,Typescript,Chart.js,Powerbi,我想为powerbi创建一个自定义的视觉效果。我正在使用chart.js和@types/chart.js。但我无法向折线图的数据集添加新的ChartPoint let p: ChartPoint = { x: data.timestamp, y: data.value, }; ds.data.push(p); 但这无法编译: TS2349:无法调用其类型缺少调

我想为powerbi创建一个自定义的视觉效果。我正在使用chart.js和@types/chart.js。但我无法向折线图的数据集添加新的ChartPoint

let p: ChartPoint = {
                        x: data.timestamp,
                        y: data.value,
                    };
ds.data.push(p);
但这无法编译:

TS2349:无法调用其类型缺少调用签名的表达式。类型“(…项:数字[])=>number)|”((…项:图表点[])=>number)”没有兼容的呼叫签名

ds类型为Chart.ChartDataSets

数据类型是Chart.ChartDataSets.data?:number[]| ChartPoint[]

但是推送方法签名是: Array.push(项目:(number&ChartPoint)[]):编号

所以我试了一下:

                    let a: (number & ChartPoint);
                    a.x = data.timestamp;
                    a.y = data.value;
                    ds.data.push(a);
但这不能使用相同的消息进行编译:

TS2349:无法调用其类型缺少调用签名的表达式。类型“(…项:数字[])=>number)|”((…项:图表点[])=>number)”没有兼容的呼叫签名

我是打字新手。我不知道如何使用push方法,也不知道为什么push方法有一个“&”交叉点类型。

您需要强制转换(typescript不知道它是number还是ChartPoint):


你能解决你的问题吗?
(ds.data as ChartPoint[]).push(p);