无法绑定到“数据”,因为它不是“画布”的已知属性

2024-01-19

我正在尝试使用 ng2-charts 并遇到错误,提示我使用的元素不正确。
我在这个网站上尝试了一些答案,但没有成功:

NG2-Charts 无法绑定到“数据集”,因为它不是“画布”的已知属性 https://stackoverflow.com/questions/40016333/ng2-charts-cant-bind-to-datasets-since-it-isnt-a-known-property-of-canvas

ng2-charts - 无法绑定到“数据集”,因为它不是“基本图表”的已知属性 https://stackoverflow.com/questions/40301229/ng2-charts-cant-bind-to-datasets-since-it-isnt-a-known-property-of-base-c

这是我的代码:

import { Component } from "@angular/core";

@Component({
    moduleId: module.id,
    templateUrl: "four-item-horse-shoe-graph.component.html",
    styleUrls: ["four-item-horse-shoe-graph.component.css"],
    selector: "four-item-horse-shoe"
})

export class FourItemHorseShoeGraphComponent {
    // Doughnut
    public doughnutChartLabels: string[] = ["Download Sales", "In-Store 
        Sales", "Mail-Order Sales"];
    public doughnutChartData: number[] = [350, 450, 100];
    public doughnutChartType: string = "doughnut";

    // events
    public chartClicked(e: any): void {
        console.log(e);
    }

    public chartHovered(e: any): void {
        console.log(e);
    }
}

和 HTML:

<div style="display: block">
<canvas baseChart
        [data]="doughnutChartData"
        [labels]="doughnutChartLabels"
        [chartType]="doughnutChartType"
        (chartHover)="chartHovered($event)"
        (chartClick)="chartClicked($event)">
</canvas>

systemjs.config.js:

            'chart': 'npm:chart.js/src/chart.js',
        "ng2-charts": "node_modules/ng2-charts"
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
        app: {
            main: './main.js',
            defaultExtension: 'js'
        },
        rxjs: {
            defaultExtension: 'js'
        },
        "ng2-charts": { main: "ng2-charts.js", defaultExtension: "js" }

应用程序模块.ts

import { ChartsModule } from "ng2-charts/ng2-charts";

declare let jQuery: Object;

@NgModule({
imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    RouterModule,
    CoreFeatureModule,
    LayoutModule,
    ChartsModule

ERROR:

Unhandled Promise rejection: Template parse errors:
Can't bind to 'data' since it isn't a known property of 'canvas'. ("<div style="display: block">
    <canvas baseChart
            [ERROR ->][data]="doughnutChartData"
            [labels]="doughnutChartLabels"
            [chartType]="doughnutCh"): FourItemHorseShoeGraphComponent@2:9
Can't bind to 'labels' since it isn't a known property of 'canvas'. ("
    <canvas baseChart
            [data]="doughnutChartData"
            [ERROR ->][labels]="doughnutChartLabels"
            [chartType]="doughnutChartType"
            (chartHover)="char"): FourItemHorseShoeGraphComponent@3:9
Can't bind to 'chartType' since it isn't a known property of 'canvas'. ("
            [data]="doughnutChartData"
            [labels]="doughnutChartLabels"
            [ERROR ->][chartType]="doughnutChartType"
            (chartHover)="chartHovered($event)"
            (chartClick)="): FourItemHorseShoeGraphComponent@4:9 ; Zone: <root> ; Task: Promise.then ; Value: SyntaxError {_nativeError: Error: Template parse errors:
Can't bind to 'data' since it isn't a known property of 'canvas'. ("<d…} Error: Template parse errors:
Can't bind to 'data' since it isn't a known property of 'canvas'. ("<div style="display: block">
    <canvas baseChart
            [ERROR ->][data]="doughnutChartData"
            [labels]="doughnutChartLabels"
            [chartType]="doughnutCh"): FourItemHorseShoeGraphComponent@2:9
Can't bind to 'labels' since it isn't a known property of 'canvas'. ("
    <canvas baseChart
            [data]="doughnutChartData"
            [ERROR ->][labels]="doughnutChartLabels"
            [chartType]="doughnutChartType"
            (chartHover)="char"): FourItemHorseShoeGraphComponent@3:9
Can't bind to 'chartType' since it isn't a known property of 'canvas'. ("
            [data]="doughnutChartData"
            [labels]="doughnutChartLabels"
            [ERROR ->][chartType]="doughnutChartType"
            (chartHover)="chartHovered($event)"
            (chartClick)="): FourItemHorseShoeGraphComponent@4:9
    at SyntaxError.BaseError [as constructor] (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:1595:29) [<root>]
    at new SyntaxError (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:1793:18) [<root>]
    at TemplateParser.parse (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:11222:21) [<root>]
    at JitCompiler._compileTemplate (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:27474:70) [<root>]
    at eval (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:27357:64) [<root>]
    at Set.forEach (native) [<root>]
    at JitCompiler._compileComponents (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:27357:21) [<root>]
    at createResult (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:27240:21) [<root>]
    at Zone.run (http://localhost:44444/node_modules/zone.js/dist/zone.js:113:43) [<root> => <root>]
    at http://localhost:44444/node_modules/zone.js/dist/zone.js:520:57 [<root>]
    at Zone.runTask (http://localhost:44444/node_modules/zone.js/dist/zone.js:151:47) [<root> => <root>]
    at drainMicroTaskQueue (http://localhost:44444/node_modules/zone.js/dist/zone.js:418:35) [<root>]
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:44444/node_modules/zone.js/dist/zone.js:349:25) [<root>]
consoleError @ zone.js:405
_loop_1 @ zone.js:434
drainMicroTaskQueue @ zone.js:438
ZoneTask.invoke @ zone.js:349
zone.js:407 Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'data' since it isn't a known property of 'canvas'. ("<div style="display: block">
    <canvas baseChart
            [ERROR ->][data]="doughnutChartData"
            [labels]="doughnutChartLabels"
            [chartType]="doughnutCh"): FourItemHorseShoeGraphComponent@2:9
Can't bind to 'labels' since it isn't a known property of 'canvas'. ("
    <canvas baseChart
            [data]="doughnutChartData"
            [ERROR ->][labels]="doughnutChartLabels"
            [chartType]="doughnutChartType"
            (chartHover)="char"): FourItemHorseShoeGraphComponent@3:9
Can't bind to 'chartType' since it isn't a known property of 'canvas'. ("
            [data]="doughnutChartData"
            [labels]="doughnutChartLabels"
            [ERROR ->][chartType]="doughnutChartType"
            (chartHover)="chartHovered($event)"
            (chartClick)="): FourItemHorseShoeGraphComponent@4:9
Error: Template parse errors:
Can't bind to 'data' since it isn't a known property of 'canvas'. ("<div style="display: block">
    <canvas baseChart
            [ERROR ->][data]="doughnutChartData"
            [labels]="doughnutChartLabels"
            [chartType]="doughnutCh"): FourItemHorseShoeGraphComponent@2:9
Can't bind to 'labels' since it isn't a known property of 'canvas'. ("
    <canvas baseChart
            [data]="doughnutChartData"
            [ERROR ->][labels]="doughnutChartLabels"
            [chartType]="doughnutChartType"
            (chartHover)="char"): FourItemHorseShoeGraphComponent@3:9
Can't bind to 'chartType' since it isn't a known property of 'canvas'. ("
            [data]="doughnutChartData"
            [labels]="doughnutChartLabels"
            [ERROR ->][chartType]="doughnutChartType"
            (chartHover)="chartHovered($event)"
            (chartClick)="): FourItemHorseShoeGraphComponent@4:9
    at SyntaxError.BaseError [as constructor] (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:1595:29) [<root>]
    at new SyntaxError (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:1793:18) [<root>]
    at TemplateParser.parse (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:11222:21) [<root>]
    at JitCompiler._compileTemplate (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:27474:70) [<root>]
    at eval (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:27357:64) [<root>]
    at Set.forEach (native) [<root>]
    at JitCompiler._compileComponents (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:27357:21) [<root>]
    at createResult (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:27240:21) [<root>]
    at Zone.run (http://localhost:44444/node_modules/zone.js/dist/zone.js:113:43) [<root> => <root>]
    at http://localhost:44444/node_modules/zone.js/dist/zone.js:520:57 [<root>]
    at Zone.runTask (http://localhost:44444/node_modules/zone.js/dist/zone.js:151:47) [<root> => <root>]
    at drainMicroTaskQueue (http://localhost:44444/node_modules/zone.js/dist/zone.js:418:35) [<root>]
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:44444/node_modules/zone.js/dist/zone.js:349:25) [<root>]
    at SyntaxError.BaseError [as constructor] (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:1595:29) [<root>]
    at new SyntaxError (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:1793:18) [<root>]
    at TemplateParser.parse (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:11222:21) [<root>]
    at JitCompiler._compileTemplate (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:27474:70) [<root>]
    at eval (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:27357:64) [<root>]
    at Set.forEach (native) [<root>]
    at JitCompiler._compileComponents (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:27357:21) [<root>]
    at createResult (http://localhost:44444/node_modules/@angular/compiler/bundles/compiler.umd.js:27240:21) [<root>]
    at Zone.run (http://localhost:44444/node_modules/zone.js/dist/zone.js:113:43) [<root> => <root>]
    at http://localhost:44444/node_modules/zone.js/dist/zone.js:520:57 [<root>]
    at Zone.runTask (http://localhost:44444/node_modules/zone.js/dist/zone.js:151:47) [<root> => <root>]
    at drainMicroTaskQueue (http://localhost:44444/node_modules/zone.js/dist/zone.js:418:35) [<root>]
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:44444/node_modules/zone.js/dist/zone.js:349:25) [<root>]
    at resolvePromise (http://localhost:44444/node_modules/zone.js/dist/zone.js:486:31) [<root>]
    at resolvePromise (http://localhost:44444/node_modules/zone.js/dist/zone.js:471:17) [<root>]
    at http://localhost:44444/node_modules/zone.js/dist/zone.js:520:17 [<root>]
    at Zone.runTask (http://localhost:44444/node_modules/zone.js/dist/zone.js:151:47) [<root> => <root>]
    at drainMicroTaskQueue (http://localhost:44444/node_modules/zone.js/dist/zone.js:418:35) [<root>]
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:44444/node_modules/zone.js/dist/zone.js:349:25) [<root>]
consoleError @ zone.js:407
_loop_1 @ zone.js:434
drainMicroTaskQueue @ zone.js:438
ZoneTask.invoke @ zone.js:349

我需要将 ChartModule 导入到我想要使用图表的组件的 module.ts 文件中。我最初只将其导入到 app.module.ts 中。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法绑定到“数据”,因为它不是“画布”的已知属性 的相关文章

随机推荐

  • 滑块输入延迟

    有没有办法使sliderInput http shiny rstudio com reference shiny latest sliderInput html等待几秒钟 然后它会更改其对应的input 多变的 我有一个栏正在控制需要根据值
  • 使用 Mac 应用程序部署 Qt 框架以及 otool 的使用

    我在使用我的 Mac 应用程序部署 Qt 框架时遇到问题 我希望有人能知道为什么当我在干净的 Mac 即不是开发人员 Mac 上运行该应用程序时会出现此错误 操作系统 10 7 2 并使用 XCode 错误消息 Library not lo
  • 如何使用列表(或元组)作为字符串格式化值

    假设这个变量 s Python rocks x s s s 0 s 1 现在我想替换更长的列表 并分别添加所有列表值 例如 s 0 s 1 s n 似乎不正确 引用自文档 给定格式 值 如果格式 需要一个参数 值可以 是单个非元组对象 4
  • 如何在 F# 中的集群配置中创建参与者

    我正在创建一个示例Akka Cluster具有三个节点 A B 和 C 其中 A 是灯塔 到目前为止 从日志来看 当没有参与者或参与者是本地的 使用创建的 时 集群工作正常spawn and spawnOpt 我想从 B 创建一个 acto
  • TextMate:注释行快捷方式不再起作用(我的瑞士布局上的 Cmd-/ 或 Cmd-Shift-7)

    一段时间以来 我在 TextMate 中遇到了一种非常奇怪的行为 I had troubles to use the keyboard shortcut for commenting a line which is Cmd or on my
  • 如何在 Swift 中为 IOS 生成 RSA 非对称密钥对?

    我需要一种在 Swift 中生成 RSA 非对称密钥对的方法 我不需要将它存储在钥匙串或任何东西中 我只需要生成一个密钥对并将两个密钥放入字符串变量中 这些密钥确实需要与另一端的 PHP 兼容 我将使用对称加密来保护私钥并将其存储在手机上
  • isset 具有可变数组键数

    该数组是多维的 并且具有可变数量的子键 例如 arr a b c X 在这种情况下为3 我想创建一个函数 它接受一个像这样的字符串a b c作为参数并检查数组中是否包含该键 然后取消设置它 unset arr a b c 如果我给它a b那
  • PySpark UDF 优化挑战

    我正在尝试优化下面的代码 当运行 1000 行数据时 大约需要 12 分钟才能完成 我们的用例需要数据大小约为 25K 50K 行 这将使此实现完全不可行 import pyspark sql types as Types import n
  • 对话框活动还会在后台恢复其他活动

    这就是场景 我的应用程序中有 2 个活动 以及一个当我单击应用程序创建的通知时启动的对话框活动 问题是 当我单击通知时 如果按主页按钮停止 则仅应显示对话框 而不应显示应用程序的其他活动 当我通过按后退按钮关闭应用程序时 对话框活动会显示对
  • 检查用户是否是 C 中的 root?

    如何验证用户是否是root 通常测试用户是否为 root 是错误的 POSIX 甚至不需要 root 用户 而是将其留给实现来确定权限如何工作 代码如 if i am root do privileged op else print err
  • PHP 字符串转十六进制

    我有一个这样的字符串 0 9A Za z 如何转换为以下形式 133 x30 55 x39 101 x2d 132 x61 55 x7a 134 x2b 57 x3d 135 x2a 有什么功能吗 function strtohex str
  • 如何对 CopyOnWriteArrayList 进行排序

    我想排序CopyOnWriteArrayList 但是当我尝试运行以下代码时 它正在投掷unsorted operation exception public class CopyOnWriteArrayListExample public
  • PHP 查找字符串中所有出现的子字符串

    我需要解析 HTML 文档并查找所有出现的字符串asdf in it 我目前已将 HTML 加载到字符串变量中 我只想要字符位置 这样我就可以循环列表以在字符串后面返回一些数据 The strpos函数仅返回first发生 回国怎么样all
  • 如何检测向量中的空值

    检测向量中的空值的最佳方法是什么 如果我有下面的向量并且想知道第四个位置为空 我该怎么做 vx lt c 1 2 3 NULL 5 is null 仅返回FALSE is null vx 1 FALSE 我想得到 FALSE FALSE F
  • 游戏中心组

    我有一款带有 Game Center 排行榜的 iOS 游戏 我几个月前发布了这款游戏 现在正在开发 OSX 版本 我想为两个版本的游戏使用相同的排行榜 这意味着我需要创建一个 Game Center 组 问题是 当您将排行榜 ID 移动到
  • 判断Android应用是否是第一次使用

    我目前正在开发一个 Android 应用程序 我需要在应用程序第一次启动时做一些事情 即代码仅在程序第一次启动时运行 您可以使用共享首选项以确定这是否是应用程序的 第一次 启动 只需使用一个布尔变量 my first time 并将其值更改
  • 流星js如何从服务器将文件写入磁盘

    我正在编写一个流星包 myPackage 它需要使用 Npm FileSystem 和 Pah 模块将文件写入磁盘 该文件最终应位于 example app packages myPackage auto generated myFile
  • 打印数组显示错误的输出

    这段代码有什么问题 我得到了错误的输出 我不知道出了什么问题 希望您能帮助我 public class Main public static void main String args int data 11 22 33 55 22 88
  • 正则表达式 匹配正则表达式

    是否可以写一个与正则表达式匹配的正则表达式 有人有例子吗 如果存在一些理论上的障碍 是否有人知道至少可以匹配最常见的正则表达式模式的正则表达式 正则表达式不是正则语言 因此不能用正则表达式来描述 Update 更有用的实用答案 您无法使用任
  • 无法绑定到“数据”,因为它不是“画布”的已知属性

    我正在尝试使用 ng2 charts 并遇到错误 提示我使用的元素不正确 我在这个网站上尝试了一些答案 但没有成功 NG2 Charts 无法绑定到 数据集 因为它不是 画布 的已知属性 https stackoverflow com qu