ng2-charts - 无法绑定到“数据集”,因为它不是“基础图表”的已知属性 [英] ng2-charts - Can't bind to 'datasets' since it isn't a known property of 'base-chart'

查看:295
本文介绍了ng2-charts - 无法绑定到“数据集”,因为它不是“基础图表”的已知属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我正在使用 ng2-charts

从ng2-charts导入不是 import {ChartsModule};
从ng2-charts / components / charts / charts;导入{ChartsModule}因为 this(issue#440)

Import not import {ChartsModule} from "ng2-charts"; but import {ChartsModule} from "ng2-charts/components/charts/charts;" because of this (issue #440)

我的整个 app.module.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 { }

ChartComponent

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 的问题。我发现用npm安装的 chart.js 在我的 index.html 中引用它时产生了404 as node_modules / chart.js / src / chart.js

I thought this might be an issue with Chart.js. And I found that the chart.js installed with npm was resulting in a 404 when referencing it in my index.html as node_modules/chart.js/src/chart.js.

所以我下载了 Chart.bundle.min.js 在此之后无效我尝试下载 Chart.js 本身。 (将其放在 src / assets / js /...中)。

So I downloaded the Chart.bundle.min.js after this didn't work I tried downloading the Chart.js itself. (placing it in src/assets/js/...).

ng2-charts\\\
g2-charts.js不会导出ChartsModule
的评论部分。但由于没有提供答案,这不是根本问题,我发布了这个。

This problem was also addressed in ng2-charts\ng2-charts.js does not export ChartsModule 's comment section. But since no answer has been provided and this wasn't the root question, I posted this one.

错误:(抑制错误消息赢了没有帮助,因为它阻止了我的应用加载)。

Error: (suppressing the errormessage won't help since it's stopping my app from loading).

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]'})

I've never used this library, but from just looking at the latest (1.4.1) version's source code, it should be used as an attribute on a canvas @Directive({selector: 'canvas[baseChart]'})

<canvas baseChart
   class="chart"
   [data]="datasets"
   [labels]="labels"
   [options]="options"
   [chartType]="'doughnut'">
</canvas>

这篇关于ng2-charts - 无法绑定到“数据集”,因为它不是“基础图表”的已知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆