巧用ngStyle动态计算图表的高度(赞,实用)

参考资料:
1、如何正确使用函数[ngStyle]

先上图:
巧用ngStyle动态计算图表的高度(赞,实用)_第1张图片

html 

{{chartBarTitle}}: 实收合计: {{totalBarValue}}

关键:
        [ngStyle]="getChartHeight()" 这行

js

// 动态计算柱状图的高度
private getChartHeight(): object {
    let barCount: number = 0;
    ...
    let h = 17 * barCount + 30 + 20 + 20;   //总行高+grid.top+grid.bottom+grid.label高度  
    if (h < 150) {
        h = 150;
    }
    return { 'height': h.toString() + 'px' };
}

计算出有多少条bar, 再乘以bar的高度
 

 


    


 

 

 

你可能感兴趣的:(ECharts,Ionic3,实用)