gpt4 book ai didi

javascript - 切换选项卡后 ionic 段不显示数据

转载 作者:搜寻专家 更新时间:2023-11-01 04:39:54 25 4
gpt4 key购买 nike

segments 切换后,我无法显示图表.我目前有 2 个段,索引和编辑。在索引上,我成功地显示了一个图表 Chart.js .

图表代码:

diagram = function() {
var finished = 0;
var pending = 0;

for (var i = 0; i < this.goal.activities.length; i++) {
var current = this.goal.activities[i];
if (current.completed == true) { finished++ } else { pending++ }
}
this.piChart = new Chart(this.piCanvas.nativeElement, {
type: 'doughnut',
data: {
labels: ["finished activities", "pending activities"],
datasets: [{
label: '# of Votes',
data: [
finished
,
pending
],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)'
],
hoverBackgroundColor: [
"#FF6384",
"#36A2EB"
]
}]
}
})
}

并调用函数:

ionViewDidEnter() {
this.diagram();
}

现在在页面上它是初始 View ,图表已成功加载并生成漂亮的 donut 。问题是在我单击一个段然后返回到初始页面(带有图表)之后。现在图表不见了。我仍然在 HTML 中看到它,但它只是不在 View 中呈现。

View 中的代码:

<ion-header>
<ion-navbar color="primary">
<ion-title>{{ goal.title }}</ion-title>
</ion-navbar>
</ion-header>

<ion-content>
<ion-segment [(ngModel)]="goalTab">
<ion-segment-button value="progress">
Progress
</ion-segment-button>
<ion-segment-button value="activities">
Actitivies
</ion-segment-button>
</ion-segment>

<div [ngSwitch]="goalTab">
<ion-card *ngSwitchCase="'progress'">
<ion-card-header>
Overview of activities for: {{ goal.title }}
</ion-card-header>
<ion-card-content>
<canvas #piCanvas></canvas>
</ion-card-content>
</ion-card>

<ion-list *ngSwitchCase="'activities'">
<ion-item>
<ion-card-header>
Something other segment
</ion-card-header>
</ion-item>
</ion-list>
</div>
</ion-content>

希望有人能够定位问题并帮助我,谢谢!

更新

带有图表的 Canvas 不在 HTML 中。在初始加载时,我看到以下内容(正确): enter image description here

在切换到另一部分并返回到应该呈现图表的部分之后(不正确): enter image description here

所以不知何故,从段切换后,图表未正确初始化。

最佳答案

在图表的 ionic 卡中试试这个:

   <ion-card [style.display]="goalTab == 'progress' ? 'block' : 'none'">
<ion-card-header>
Overview of activities for: {{ goal.title }}
</ion-card-header>
<ion-card-content>
<canvas #piCanvas></canvas>
</ion-card-content>
</ion-card>

关于javascript - 切换选项卡后 ionic 段不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44605562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com