Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/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
Ionic framework 爱奥尼亚5中的Chart.js_Ionic Framework - Fatal编程技术网

Ionic framework 爱奥尼亚5中的Chart.js

Ionic framework 爱奥尼亚5中的Chart.js,ionic-framework,Ionic Framework,我一直试图通过查看本教程()来使用Ionic 5中的Chart.js 但我得到了这个错误: 除了文件名外,代码几乎相同。 我真的不明白为什么会这样,欢迎任何帮助 import { Component, AfterViewInit, ViewChild , ElementRef } from '@angular/core'; import {Chart} from "chart.js"; @Component({ selector: 'app-tab3', temp

我一直试图通过查看本教程()来使用Ionic 5中的Chart.js 但我得到了这个错误:

除了文件名外,代码几乎相同。 我真的不明白为什么会这样,欢迎任何帮助

import { Component, AfterViewInit, ViewChild , ElementRef } from '@angular/core';
import {Chart} from "chart.js";

@Component({
  selector: 'app-tab3',
  templateUrl: 'tab3.page.html',
  styleUrls: ['tab3.page.scss']
})
export class Tab3Page implements AfterViewInit{
  @ViewChild('lineCanvas') private lineCanvas: ElementRef;

  lineChart: any;

  constructor() { }

  ngAfterViewInit() {
    this.lineChartMethod();
  }

  lineChartMethod() {
    this.lineChart = new Chart(this.lineCanvas.nativeElement, {
      type: 'line',
      data: {
        labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'November', 'December'],
        datasets: [
          {
            label: 'Sell per week',
            fill: false,
            //lineTension: 0.1,
            backgroundColor: 'rgba(75,192,192,0.4)',
            borderColor: 'rgba(75,192,192,1)',
            borderCapStyle: 'butt',
            borderDash: [],
            borderDashOffset: 0.0,
            borderJoinStyle: 'miter',
            pointBorderColor: 'rgba(75,192,192,1)',
            pointBackgroundColor: '#fff',
            pointBorderWidth: 1,
            pointHoverRadius: 5,
            pointHoverBackgroundColor: 'rgba(75,192,192,1)',
            pointHoverBorderColor: 'rgba(220,220,220,1)',
            pointHoverBorderWidth: 2,
            pointRadius: 1,
            pointHitRadius: 10,
            data: [65, 59, 80, 81, 56, 55, 40, 10, 5, 50, 10, 15],
            spanGaps: false,
          }
        ]
      }
    });
  }
}
这是HTML

<ion-content [fullscreen]="true">
   <div class="ion-padding">
    <ion-card>
      <ion-card-header>
        Line Chart
      </ion-card-header>
      <ion-card-content>
        <canvas #lineCanvas style="position: relative; height:20vh; width:40vw"></canvas>
      </ion-card-content>
    </ion-card>
  </div>
</ion-content>

折线图

Chart.js需要在加载数据之前注册控制器,但不管下面的机制如何,这里是Chart.js文档中初始化typescript图表的正确方法:

还可以使用简短的注册格式快速注册 一切

从'Chart.js'导入{Chart,registerables}; 图.登记册(…登记册)

最后还有一个单独的 仅在一行中为您执行上述操作的路径:

从“Chart.js/auto”导入图表


来源:

Chart.js需要在加载数据之前注册控制器,但不管下面的机制如何,这里是Chart.js文档中初始化typescript中图表的正确方法:

还可以使用简短的注册格式快速注册 一切

从'Chart.js'导入{Chart,registerables}; 图.登记册(…登记册)

最后还有一个单独的 仅在一行中为您执行上述操作的路径:

从“Chart.js/auto”导入图表


资料来源:

成功了,非常感谢!不客气!它成功了,非常感谢你!不客气!