angular - 为什么我的图形不显示?页面是白色的
问题描述
我在这里按照第一个教程进行操作,但我的图形没有出现?页面是白色的...
我不明白为什么?我在Stackblitz上写了代码,因为我真的很想了解这个问题。
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ChartsModule } from 'ng2-charts';
@NgModule({
imports: [ BrowserModule, FormsModule, ChartsModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
折线图/折线图.component.ts
import { Component, OnInit } from '@angular/core';
import { ChartDataSets, ChartOptions } from 'chart.js';
import { Color, Label } from 'ng2-charts';
@Component({
selector: 'app-line-chart',
templateUrl: './line-chart.component.html',
styleUrls: ['./line-chart.component.css']
})
export class LineChartComponent implements OnInit {
public lineChartData: ChartDataSets[] = [
{ data: [61, 59, 80, 65, 45, 55, 40, 56, 76, 65, 77, 60], label: 'Apple' },
{ data: [57, 50, 75, 87, 43, 46, 37, 48, 67, 56, 70, 50], label: 'Mi' },
];
public lineChartLabels: Label[] = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
public lineChartOptions = {
responsive: true,
};
public lineChartLegend = true;
public lineChartType = 'line';
public lineChartPlugins = [];
constructor() { }
ngOnInit() {
}
}
折线图/折线图.component.html
<div style="display: block;">
<canvas baseChart width="500" height="200"
[datasets]="lineChartData"
[labels]="lineChartLabels"
[options]="lineChartOptions"
[legend]="lineChartLegend"
[chartType]="lineChartType"
[plugins]="lineChartPlugins">
</canvas>
</div>
谢谢
解决方案
推荐阅读
- java - 应用程序保持强制停止
- tmux - 你可以使用转义序列来改变 tmux 状态栏的颜色吗?
- javascript - Vue中如何设置父组件的样式
- sql-server - 如果 IN 运算符的子查询失败会怎样?
- python - 如何导出数据,例如从 Chrome 扩展的 console.log() 到 Python 脚本
- firebase - 如何在 Firestore 文档中自动生成一个值?
- c++ - 纹理视图,GL_DEPTH_STENCIL_TEXTURE_MODE 参数设置为 GL_STENCIL_INDEX 和 Intel GPU
- javascript - 在开发者控制台中实例化类
- c# - 在 C# 中使用丢弃运算符“_”是否会以任何方式优化代码?
- json - Excel VBA REST API 连接 POST json 语法错误