html - 在我使用 CanvasJS、HTML 和 Angular 调整浏览器窗口大小之前,条形图不会显示
问题描述
我使用 CanvasJS、HTML 和 angular 制作了条形图,我面临的问题是条形图仅在我调整浏览器大小时显示,我该如何解决这个问题。
打字稿代码是:
import { Component, OnInit } from '@angular/core';
import * as CanvasJS from 'node_modules/canvasjs/dist/canvasjs.min'
@Component({
selector: 'app-c2',
templateUrl: './c2.component.html',
styleUrls: ['./c2.component.css']
})
export class C2Component implements OnInit {
constructor(){
}
ngOnInit() {
let chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
exportEnabled: true,
title: {
text: "Basic Column Chart in Angular"
},
data: [{
type: "column",
dataPoints: [
{ y: 71, label: "Apple" },
{ y: 55, label: "Mango" },
{ y: 50, label: "Orange" },
{ y: 65, label: "Banana" },
{ y: 95, label: "Pineapple" },
{ y: 68, label: "Pears" },
{ y: 28, label: "Grapes" },
{ y: 34, label: "Lychee" },
{ y: 14, label: "Jackfruit" },
{ y: 14, label: "Guava" }
]
}]
});
chart.render();
}
}
HTML 代码是:
<div id="chartContainer" style="height: 55%; width: 55%;" ></div>
解决方案
推荐阅读
- javascript - 如果不存在参数,如何将动作传递给另一个动作 ReactJs
- mysql - mysql中的'<=>'和'is'有什么区别?
- flutter - Flutter - 在其他模型中导入模型
- c++ - 在连接到容器后或编译/调试之前运行脚本以在 VSCode 中设置环境
- angular - 如何在不使用 TableModel 的情况下在 Angular Carbon 设计系统中实现分页?
- python - 使用笔记本时,Tkinter 条目小部件不会接受输入
- vue.js - 将 npm 模块添加到 Piranha CMS
- c# - 如何将文件写入 .NET Core 中的项目文件夹?
- javascript - React:为什么这些组件在 useState 发生变化时没有更新?(应用挂载后渲染的组件)
- verilog - ShiftRegister Verilog HDL 输出给出 xxxxxxx