angular - ng-2 图表无响应
问题描述
我正在使用 ng2 图表。我有一个日期选项卡,我可以在其中选择今天、星期、月份和特定日期。据此,我的数据在图表中有所不同。根据日期,我的数据运行良好。但是我的图表响应速度不够快,无法绘制与日期对应的值。
今日查看:https : //ibb.co/bHDdwLG 数据[100,105,120],
周视图:https : //ibb.co/SfWxyMr 数据[100,105,120,140]
如果您查看周视图,则在完成 value:140 图表之前,它似乎没有响应。
代码
TS
public lineChartOptions: any = {
responsive: true,
};
getabc(start?: moment.Moment, end?: moment.Moment) {
this.abcService.getabc(this.token, start, end).subscribe(
data => {
this.a = data.map(k => k.a);
this.date_time = data.map(k => k.datetime.toLocaleTimeString());
this.lineChartData = [
{ data: this.a, label: 'abc' }
]
this.lineChartLabels=this.date_time
console.log(this.a);
console.log(this.date_time); // I can get the values correctly
according to the date
}
);
}
HTML
<div style="display: block;" *ngIf="lineChartData.length > 0">
<canvas baseChart width="400" height="180" style="margin-
left:5%;margin-top: 5%;" [datasets]="lineChartData"
[labels]="lineChartLabels" [options]="lineChartOptions"
[colors]="lineChartColors" [legend]="lineChartLegend"
[chartType]="lineChartType" (chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)"></canvas>
</div>
</div>
解决方案
您需要将维护AspectRatio 设置为 false
public pieChartOptions: ChartOptions = {
responsive: true,
maintainAspectRatio: false,
}
并设置画布高度 => 画布 baseChart height="450"
<canvas baseChart height="450"
[data]="pieChartData"
[labels]="pieChartLabels"
[chartType]="pieChartType"
[options]="pieChartOptions"
[plugins]="pieChartPlugins"
[colors]="pieChartColors"
[legend]="pieChartLegend"
(chartClick)="chartClicked($event)">
</canvas>
您可以使用 CSS 设置移动高度
@media (max-width: 600px) {
.chartjs-render-monitor {
height: 700px !important;
}
}
推荐阅读
- arrays - ArraySort 回调未按正确顺序对我的数组进行排序
- r - 如何使用 plot3D::persp3D() 像使用 rgl::persp3d() 一样在 rgl 设备中查看绘图?
- html - 我的日期字段在 IE8 中运行良好,但在 IE11 中运行不正常
- bash - 不能在 mv 命令中使用此变量
- c# - 实体框架上下文 SqlQuery
对于存储过程返回 SqlParameter 已被另一个 SqlParameterCollection 包含 - c - 在c中使用信号量同步两个子进程
- angular - 如果一个 observable 正在进行,订阅它,如果没有,重新启动它
- javascript - 这些出口在功能上是否相同?
- node.js - 如何获取mongodb中不同元素的最大值?
- complex-numbers - 复数的类型类