使用Ionic&Angular根据点击事件(不同的视图)动态加载多个ChartJS

我是Ionic框架的新手。帮助我解决以下问题。

charts.page.html:

<ion-content>
    <ion-toolbar>
        <ion-segment [(ngModel)]="default" *ngFor="let chart of chartList">
            <ion-segment-button value={{chart.value}}>
                <ion-icon [icon]="chart.icon"></ion-icon>
            </ion-segment-button>
        </ion-segment>
    </ion-toolbar>
    <div [ngSwitch]="default">
        <div *ngSwitchCase="'HBar'">
            <app-hbar-chart></app-hbar-chart>
        </div>
        <div *ngSwitchCase="'Pie'">
            <app-pie-chart></app-pie-chart>
        </div>
        <div *ngSwitchCase="'VBar'">
            <app-vbar-chart></app-vbar-chart>
        </div>
    </div>
</ion-content>

pie-chart.component.html:

<div>
    <p-chart #pieSketch type="pie" [data]="chartPieData" (onDataSelect)="pieDataSelected($event)"
        [options]="chartPieOption" [width]="chartPieWidth" [height]="chartPieHeight"></p-chart>
</div>

我正在使用PrimeNg ChartJs。 (类似于为水平和垂直条形图创建的另外两个组件。)

pie-chart.component.ts:

...
ngOnInit() {

this.chartService.emitChartData.subscribe(data => {
this.chartPieData = data; // Here i'm getting the chartData successfully from back-end
});

}

上面的代码按预期方式工作,并且可以切换图表视图。我可以在不同的视图上看到数据渲染 成功。 但是,当我应用过滤器并尝试刷新图表数据时,只有默认选项段视图在 更新的其他内容保持不变,当我在视图之间切换时,它会重新渲染。

我尝试了所有可能的方法来刷新ChartJS功能中提供的图表,它仅适用于 默认细分,则只有在视图之间切换时,其他视图才会更新。 不起作用)

请帮助我是否可以使用离子段来完成在不同视图中绘制图表的方法? 如果我们使用angular指令并单独托管不同的图表以使其也可以与过滤器一起使用,则是可行的。

iCMS 回答:使用Ionic&Angular根据点击事件(不同的视图)动态加载多个ChartJS

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1716226.html

大家都在问