ng2-charts - 无法绑定到“数据集”,因为它不是“基本图表”的已知属性

2023-11-21

版本:Cordova:6.3.1,Gulp CLI:1.2.2,Ionic 框架:2.0.0-rc.0,Ionic CLI 版本:2.1.0


我在用着ng2 图表在我的 ionic2 应用程序中。

导入不import {ChartsModule} from "ng2-charts"; but import {ChartsModule} from "ng2-charts/components/charts/charts;"因为这个(问题#440)

我的整个应用程序模块.ts

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { ChartsModule } from 'ng2-charts/components/charts/charts';

import { MyApp } from './app.component';
import { EventsPage } from '../pages/events/events.component';
import { ChartComponent } from '../pages/chart/chart.component';
import { APICaller } from '../services/APICaller.service';
import { EventDetailComponent } from '../pages/event-detail/event-detail.component';
import { ParticipantDetail } from '../pages/participant-detail/participant-detail.component';
import { ParticipantFeedComponent } from '../pages/participant-feed/participant-feed.component';



@NgModule({
  declarations: [
    MyApp,
    EventsPage,
    EventDetailComponent,
    ParticipantDetail,
    ParticipantFeedComponent,
    ChartComponent
  ],
  imports: [
    IonicModule.forRoot(MyApp),
    ChartsModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    EventsPage,
    EventDetailComponent,
    ParticipantDetail,
    ParticipantFeedComponent,
    ChartComponent
  ],
  providers: [APICaller]
})
export class AppModule { }

图表组件:

import { Component, OnInit } from '@angular/core';
@Component({
    selector: 'pie-chart',
    template: `

<base-chart
    class="chart"
    [datasets]="datasets"
    [labels]="labels"
    [options]="options"
    [chartType]="'doughnut'">Titel?
</base-chart>

`
})
export class ChartComponent implements OnInit {
    private datasets = [
        {
            label: "# of Votes",
            data: [12,19,3,5,2,3]
        }
    ];


    private labels = ['Red', 'blue', 'yellow', 'green', 'purple', 'orange'];

    private options = {
        scales: {
            yAxes: [{
                beginAtZero: true
            }]
        }
    };

    constructor() {

    }

    ngOnInit() { }
}

我认为这可能是一个问题Chart.js。我发现chart.js使用 npm 安装时在我的引用中引用它时导致 404index.html as node_modules/chart.js/src/chart.js.

所以我下载了Chart.bundle.min.js在这不起作用之后我尝试下载Chart.js本身。 (将其放入src/assets/js/...).

这个问题也被解决在ng2-charts\ng2-charts.js 不导出 ChartsModule的评论区。但由于没有提供答案,而且这不是根本问题,所以我发布了这个。

Error:(抑制错误消息不会有帮助,因为它会阻止我的应用程序加载)。

polyfills.js:3 Unhandled Promise rejection: Template parse errors:
Can't bind to 'datasets' since it isn't a known property of 'base-chart'.
1. If 'base-chart' is an Angular component and it has 'datasets' input, then verify that it is part of this module.
2. If 'base-chart' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message.
 ("
    class="chart"

    [ERROR ->][datasets]="datasets"

    [labels]="labels"
"): ChartComponent@4:4
Can't bind to 'labels' since it isn't a known property of 'base-chart'.
1. If 'base-chart' is an Angular component and it has 'labels' input, then verify that it is part of this module.
2. If 'base-chart' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message.
 ("
    [datasets]="datasets"

    [ERROR ->][labels]="labels"

    [options]="options"
"): ChartComponent@6:4

我从来没有使用过这个库,但只是看看最新(1.4.1)版本的源代码,它应该用作画布上的属性@Directive({selector: 'canvas[baseChart]'})

<canvas baseChart
   class="chart"
   [data]="datasets"
   [labels]="labels"
   [options]="options"
   [chartType]="'doughnut'">
</canvas>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ng2-charts - 无法绑定到“数据集”,因为它不是“基本图表”的已知属性 的相关文章

随机推荐

  • 比较时,不带键字段的 VB.NET 匿名类型与 C# 匿名类型有何不同?

    我对此感到摸不着头脑 因为我无法理解为什么会发生以下情况 VB NET Dim product1 New With Name paperclips Price 1 29 Dim product2 New With Name papercli
  • npm 安装失败

    首先我要说的是 我几乎没有在终端或使用 Node js 工作的经验 同事去度假了 我正在尝试按照他留下的说明在我们的演示服务器上设置他的应用程序 我可以让所有内容在本地运行 但在安装 socket io 模块的服务器上遇到问题 安装了pyt
  • 产品平面表不会重新索引 - 行大小太大

    当我尝试重新索引产品平面数据时 我得到There was a problem with reindexing process 数据库修复没有帮助 Exception log 文件显示此错误 2011 08 29T11 54 05 00 00
  • IE 10 中的 event.preventDefault

    我正在提交一个表单 并且我想阻止提交操作 直到我执行一些其他操作 例如显示文件上传进度条 我根据诸如此类的问题设置了此代码event preventDefault 函数在 IE 中不起作用 document ready function f
  • 如何在 Twig 日期过滤器中使用时区?

    我正在使用 Twig 和这个日期过滤器 http www twig project org doc templates html date 显然他们正在寻找参数中的 DateTime 实例 看着这个http www php net manu
  • 提要对话框:图片未显示

    我的 Facebook 提要对话框链接正确呈现了对话框页面 但使用图片参数设置的图像未显示 只是表示没有图片的灰线 我已经更改了图片文件和类型几次 但图像仍然不显示 这是代码 share url https www facebook com
  • Python的打印函数在调用时会刷新缓冲区? [复制]

    这个问题在这里已经有答案了 我有以下代码来刷新输出缓冲区 print return 1 sys stdout flush 我可以设置打印函数 以便它在调用时自动刷新缓冲区吗 您可以使用 u 标志以无缓冲模式启动 python 例如 pyth
  • java.lang.NoSuchMethodError: org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont.addNewFamily()

    将 poi 升级到版本并添加来自 apache 站点的 jar 包 但是出现以下错误 java lang NoSuchMethodError org openxmlformats schemas spreadsheetml x2006 ma
  • 将查询字符串解析为数组

    我怎样才能转一个string下面进入array pg id 2 parent id 2 document video 这就是我正在寻找的数组 array pg id gt 2 parent id gt 2 document gt video
  • 泛型函数类型别名

    为什么在 TypeScript 中类型别名不能与泛型函数一起使用 例如 这里 TS 没有将 Identical 类型定义为泛型 type Identical
  • Django ALLOWED_HOSTS 通过 Apache 接受本地 IP

    我正在使用 Apache 提供 Django 应用程序 在 Django 的 settings py 中我有DEBUG False 因此我必须允许一些主机 例如 ALLOWED HOSTS dyndns org localhost 这工作正
  • Keras 自定义损失作为多个输出的函数

    我使用 keras 一个卷积网络 构建了一个自定义架构 该网络有 4 个头 每个头输出不同大小的张量 我正在尝试编写一个自定义损失函数作为这 4 个输出的函数 我之前一直在实施自定义损失 但它要么是每个头的不同损失 要么是每个头的相同损失
  • 在“DELETE FROM table”之后更改 sqlite 文件大小

    我正在使用 sqlite3 文件 首先 我进入了比较大的数据库 文件大小约为100 MB 比我做的 db gt exec DELETE FROM table 并只输入了该数据库的一小部分 但文件大小仍为 100 MB 删除 sqlite 文
  • Android:从回调中获取结果(网络 KOUSH ION)

    对于我的应用程序 我需要从我们的服务器联系我们的 API 该服务器返回一些 JSON 下载 JSON 时 它应该显示一个进度条 我想我应该使用Android的AsyncTask在进行网络操作时处理 GUI 所以我在我的文件中编写了以下内容A
  • 如何最好地处理 C/C++ 中的动态多维数组?

    在 C 和 或 C 中操作动态 所有维度直到运行时才知道 多维数组的可接受 最常用的方法是什么 我正在尝试找到最简洁的方法来完成此 Java 代码的功能 public static void main String args Scanner
  • std::move 和 RVO 优化

    我最近读过如何std move可以通过仅移动值而不是复制它们来加速代码 所以我做了一个测试程序来比较速度std vector 代码 include
  • Node.js 服务器超时问题(EC2 + Express + PM2)

    我对运行生产 Node js 应用程序还比较陌生 最近我遇到了服务器超时的问题 基本上在一定的使用量和时间后 我的 Node js 应用程序停止响应请求 我什至不再看到在我的控制台上触发路由 就好像整个事情都停止了 来自我的客户端 运行 A
  • 如何使用 Odoo 中的方法设置默认值?

    如何计算 Odoo 8 中对象字段中的默认值模型 py 我们不能使用 defaultOdoo 8 中不再有属性 field name fields datatype string value default compute default
  • FileUpload:未找到 DeferredFileOutputStream 类? [复制]

    这个问题在这里已经有答案了 我正在使用 apache FileUpload 来处理 文件上传 我将它与码头一起使用 servlet 看到多部分请求 但在执行时抛出 NoClassDefFoundError 异常 protected void
  • ng2-charts - 无法绑定到“数据集”,因为它不是“基本图表”的已知属性

    版本 Cordova 6 3 1 Gulp CLI 1 2 2 Ionic 框架 2 0 0 rc 0 Ionic CLI 版本 2 1 0 我在用着ng2 图表在我的 ionic2 应用程序中 导入不import ChartsModule