要求:原始数据中不能出现单位和%等,只能出现数字
可在订阅到数据后对数据进行大小转换和字符串拼接。
//数据放置在assets目录下的json文件中
[{
"resource": "CPU_numbers",
"threshold_value": 6,
"colorType": "#ffe608"
}, {
"resource": "CPU_usage",
"threshold_value": 0.7,
"colorType": "#fdd98d"
}, {
"resource": "memory_size",
"threshold_value": 2048,
"colorType": " #f68b39"
}, {
"resource": "memory_usage",
"threshold_value": 0.8,
"colorType": "#e43232"
}]
// 通过HttpClient访问数据,从Observable中订阅到数据后进行数值转换和字符串拼接
private initData(): any {
this.jData.getData().subscribe(data=>{
data[1].threshold_value=parseFloat(data[1].threshold_value)*100+"%";
data[2].threshold_value=parseInt(data[2].threshold_value)/1024+"GB";
data[3].threshold_value=parseFloat(data[3].threshold_value)*100+"%";
this.data=data;
});
}