简体   繁体   English

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

[英]Can't bind to 'datasets' since it isn't a known property of 'canvas'

this is my app.module.ts I try with a tutorial this ng2-charts这是我的 app.module.ts 我尝试使用ng2-charts教程

import { ChartsModule } from 'ng2-charts';
imports: [
 ChartsModule
],

this is my html code page.html, i copy and paste from the tutorial这是我的 html 代码 page.html,我从教程中复制并粘贴

< div >
 < div style = "display: block" >
  < canvas baseChart
    [datasets] = "barChartData"
    [labels] = "barChartLabels"
    [options] = "barChartOptions"
    [legend] = "barChartLegend"
    [chartType] = "barChartType"
    (chartHover) = "chartHovered($event)"
    (chartClick) = "chartClicked($event)" > 
   < /canvas>
 </ div >
 < button (click) = "randomize()" > Update < /button>
</ div >

this is my typescript page also i copy and paste from tutorial.这是我的打字稿页面,我也从教程中复制和粘贴。 page.ts页面.ts

public barChartOptions:any = {
scaleShowVerticalLines: false,
responsive: true};

public barChartLabels:string[] = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
public barChartType:string = 'bar';
public barChartLegend:boolean = true;

public barChartData:any[] = [
    {data: [65, 59, 80, 81, 56, 55, 40], label: 'Series A'},
    {data: [28, 48, 40, 19, 86, 27, 90], label: 'Series B'}
  ];

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

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

public randomize():void {
    // Only Change 3 values
    let data = [
      Math.round(Math.random() * 100),
      59,
      80,
      (Math.random() * 100),
      56,
      (Math.random() * 100),
      40];
    let clone = JSON.parse(JSON.stringify(this.barChartData));
    clone[0].data = data;
    this.barChartData = clone;
  }

I try all tutorials and examples but i don't know what happen.我尝试了所有教程和示例,但我不知道会发生什么。 i get this error.我收到这个错误。 Error detail is:错误详情是:

**Error: Template parse errors:
Can't bind to 'datasets' since it isn't a known property of 'canvas'. ("
          <div style="display: block">
            <canvas baseChart
                    [ERROR ->][datasets]="barChartData"
                    [labels]="barChartLabels"
                    [options]"): ng:///StatsPageModule/StatsPage.html@33:20
Can't bind to 'labels' since it isn't a known property of 'canvas'. ("
            <canvas baseChart
                    [datasets]="barChartData"
                    [ERROR ->][labels]="barChartLabels"
                    [options]="barChartOptions"
                    [legend"): ng:///StatsPageModule/StatsPage.html@34:20
Can't bind to 'options' since it isn't a known property of 'canvas'. ("        [datasets]="barChartData"
                    [labels]="barChartLabels"
                    [ERROR ->][options]="barChartOptions"
                    [legend]="barChartLegend"
                    [chartT"): ng:///StatsPageModule/StatsPage.html@35:20
Can't bind to 'legend' since it isn't a known property of 'canvas'. ("      [labels]="barChartLabels"
                    [options]="barChartOptions"
                    [ERROR ->][legend]="barChartLegend"
                    [chartType]="barChartType"
                    (chartHo"): ng:///StatsPageModule/StatsPage.html@36:20
Can't bind to 'chartType' since it isn't a known property of 'canvas'. ("      [options]="barChartOptions"
                    [legend]="barChartLegend"
                    [ERROR ->][chartType]="barChartType"
                    (chartHover)="chartHovered($event)"
                  "): ng:///StatsPageModule/StatsPage.html@37:20**

I just want to make a graph that says the number of users and number of posts created during a week, but every tutorial that I follow I get error, all without exception, sorry my English is not native in case you have some spelling error.我只想制作一个图表,显示一周内创建的用户数量和帖子数量,但是我遵循的每个教程都会出错,无一例外,抱歉,如果您有拼写错误,我的英语不是母语。

It's a clash between versions of Angular and ng2-charts With Angular 7.2.0 , I uninstalled ng2-charts and installed ng2-charts@2.2.3这是 Angular 和 ng2-charts 版本之间的冲突使用 Angular 7.2.0,我卸载了 ng2-charts 并安装了 ng2-charts@2.2.3

This is helped.这是有帮助的。 for more info.了解更多信息。 see: https://github.com/valor-software/ng2-charts/issues/1115见: https : //github.com/valor-software/ng2-charts/issues/1115

Setting up a chart in an Ionic App using Highcharts使用 Highcharts 在 Ionic 应用程序中设置图表

Install Highcharts for ionic:为离子安装 Highcharts:

 npm install highcharts –save

Open the file ./src/pages/home/home.html and replace everything inside the ion-content tag with a div like this.打开文件./src/pages/home/home.html并用这样的 div 替换 ion-content 标签内的所有内容。

<div id="container" style="display: block;" ></div>

This div is a container to hold the chart.这个 div 是一个容器来保存图表。 I write the code in home.ts file.我在home.ts文件中编写代码。 The home.html and home.ts are the files in charge of creating the home page in the app. home.htmlhome.ts是负责在应用程序中创建主页的文件。 In home.ts, on the top, import the highcharts module first.在 home.ts 中,首先导入highcharts模块。

import * as HighCharts from 'highcharts';

Next, create a function called ionViewDidLoad() inside the HomePage class, just after the constructor.接下来,在HomePage类中创建一个名为ionViewDidLoad()的函数,就在构造函数之后。 The file should look like this:该文件应如下所示:

import {
  Component
} from '@angular/core';
import {
  NavController
} from 'ionic-angular';
import * as HighCharts from 'highcharts';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController) {}

  ionViewDidLoad() {}
}

The ionViewDidLoad is a special function which is executed after the View has been initialized and loaded; ionViewDidLoad是一个特殊的函数,它在 View 初始化和加载后执行; this makes sure to avoid any errors during the components' access in the view.这确保避免在视图中访问组件期间出现任何错误。 Create a new HighCharts.chart object in the ionViewDidLoad :ionViewDidLoad 中创建一个新的HighCharts.chart对象:

var myChart = HighCharts.chart('container', {
  chart: {
    type: 'bar'
  },
  title: {
    text: 'Fruit Consumption'
  },
  xAxis: {
    categories: ['Apples', 'Bananas', 'Oranges']
  },
  yAxis: {
    title: {
      text: 'Fruit eaten'
    }
  },
  series: [{
    name: 'Jane',
    data: [1, 0, 4]
  }, {
    name: 'John',
    data: [5, 7, 3]
  }]
});

Save the file, and in the terminal type ionic serve –l to run the app in the browser in the lab mode.保存文件,并在终端中输入ionic serve –l以实验室模式在浏览器中运行应用程序。 The app should look like this:该应用程序应如下所示:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NG2-Charts 无法绑定到“数据集”,因为它不是“画布”的已知属性 - NG2-Charts Can't bind to 'datasets' since it isn't a known property of 'canvas' NG2-Charts模板解析错误:无法绑定到“数据集”,因为它不是“ canvas”的已知属性 - NG2-Charts Template parse errors: Can't bind to 'datasets' since it isn't a known property of 'canvas' 无法绑定到“ chartType”,因为它不是“ canvas”的已知属性 - Can't bind to 'chartType' since it isn't a known property of 'canvas' 具有Angular 4的ng2-chart:无法绑定到“数据”,因为它不是“ canvas”的已知属性 - ng2-chart with Angular 4: Can't bind to 'data' since it isn't a known property of 'canvas' 无法绑定到“控件”,因为它不是(myComponent)的已知属性 - Can't bind to 'control' since it isn't a known property of (myComponent) 无法绑定到“ useStickyClasses”,因为它不是“ div”的已知属性 - Can't bind to 'useStickyClasses' since it isn't a known property of 'div' Angular 7:无法绑定到“元素”,因为它不是 - Angular 7 : Can't bind to 'element' since it isn't a known property of 无法绑定到“ngModel”,因为它不是“输入”的已知属性 - Can't bind to 'ngModel' since it isn't a known property of 'input' 无法绑定到“matMenuTrigger”,因为它不是“a”的已知属性 - Can't bind to 'matMenuTrigger' since it isn't a known property of 'a' 无法绑定,因为它不是选择器组件的已知属性 - Can't bind to since it isn't a known property of selector component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM