gpt4 book ai didi

javascript - highchart 旭日百分比,不是相对百分比,而是取决于其他属性

转载 作者:行者123 更新时间:2023-12-03 00:40:56 25 4
gpt4 key购买 nike

我用 Angular 制作了一个森伯斯特 Highcharts 。对于第一级,我直接计算所有其他级别的总和,对于第三级,我使用了 point.value ,它也是 passAssetCnt/totalAssetCnt * 100 但对于第二级,这样就不行了。

这是我的格式化函数。我的目标是计算百分比,如果它们具有相同的 reqnum,则为 passAssetCnt/totalAssetCnt * 100

一切都很好,直到我做出将绘制百分比的返回声明而且一切都归零。

我尝试在格式化程序函数中调用一个单独的函数,该函数将完成所有这些操作,但也没有被调用。

JS FIDDLE LINK

var data = [{"id":"CSA-CCM","parent":"","name":"CSA-CCM"},{"id":"Application & Interface Security","parent":"CSA-CCM","name":"Application & Interface Security","complianceId":4,"inclusionId":1,"passAssetCnt":821,"totalAssetCnt":1198,"layer":"second","reqnum":1},{"id":"Audit Assurance & Compliance\r\n","parent":"CSA-CCM","name":"Audit Assurance & Compliance\r\n","complianceId":4,"inclusionId":13,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":2},{"id":"Business Continuity & Operational Resilience","parent":"CSA-CCM","name":"Business Continuity & Operational Resilience","complianceId":4,"inclusionId":1,"passAssetCnt":2,"totalAssetCnt":279,"layer":"second","reqnum":3},{"id":"Change Control & Configuration Management\r\n","parent":"CSA-CCM","name":"Change Control & Configuration Management\r\n","complianceId":4,"inclusionId":1,"passAssetCnt":7,"totalAssetCnt":10,"layer":"second","reqnum":4},{"id":"Data Security & Information Lifecycle ","parent":"CSA-CCM","name":"Data Security & Information Lifecycle ","complianceId":4,"inclusionId":13,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":5},{"id":"Datacenter Security","parent":"CSA-CCM","name":"Datacenter Security","complianceId":4,"inclusionId":13,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":6},{"id":"Encryption & Key Management","parent":"CSA-CCM","name":"Encryption & Key Management","complianceId":4,"inclusionId":1,"passAssetCnt":9,"totalAssetCnt":36,"layer":"second","reqnum":7},{"id":"Governance and Risk Management\r\n","parent":"CSA-CCM","name":"Governance and Risk Management\r\n","complianceId":4,"inclusionId":13,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":8},{"id":"Human Resources","parent":"CSA-CCM","name":"Human Resources","complianceId":4,"inclusionId":1,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":9},{"id":"Identity & Access Management\r\n","parent":"CSA-CCM","name":"Identity & Access Management\r\n","complianceId":4,"inclusionId":1,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":10},{"id":"Infrastructure & Virtualization Security","parent":"CSA-CCM","name":"Infrastructure & Virtualization Security","complianceId":4,"inclusionId":13,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":11},{"id":"Supply Chain Management, Transparency, and Accountability\r\n","parent":"CSA-CCM","name":"Supply Chain Management, Transparency, and Accountability\r\n","complianceId":4,"inclusionId":1,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":14},{"id":"Threat and Vulnerability Management","parent":"CSA-CCM","name":"Threat and Vulnerability Management","complianceId":4,"inclusionId":3,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":15},{"id":"AIS-01","parent":"Application & Interface Security","name":"AIS-01","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":1},{"id":"AIS-02","parent":"Application & Interface Security","name":"AIS-02","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":1},{"id":"AIS-03","parent":"Application & Interface Security","name":"AIS-03","value":28,"passAssetCnt":37,"totalAssetCnt":130,"layer":"third","reqnum":1},{"id":"AIS-04","parent":"Application & Interface Security","name":"AIS-04","value":69,"passAssetCnt":821,"totalAssetCnt":1198,"layer":"third","reqnum":1},{"id":"AAC-01","parent":"Audit Assurance & Compliance\r\n","name":"AAC-01","value":100,"passAssetCnt":1,"totalAssetCnt":1,"layer":"third","reqnum":2},{"id":"AAC-02","parent":"Audit Assurance & Compliance\r\n","name":"AAC-02","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":2},{"id":"AAC-03","parent":"Audit Assurance & Compliance\r\n","name":"AAC-03","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":2},{"id":"BCR-07","parent":"Business Continuity & Operational Resilience","name":"BCR-07","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":3},{"id":"BCR-09","parent":"Business Continuity & Operational Resilience","name":"BCR-09","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":3},{"id":"BCR-11","parent":"Business Continuity & Operational Resilience","name":"BCR-11","value":1,"passAssetCnt":2,"totalAssetCnt":279,"layer":"third","reqnum":3},{"id":"CCC-04","parent":"Change Control & Configuration Management\r\n","name":"CCC-04","value":70,"passAssetCnt":7,"totalAssetCnt":10,"layer":"third","reqnum":4},{"id":"DSI-01","parent":"Data Security & Information Lifecycle ","name":"DSI-01","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":5},{"id":"DSI-03","parent":"Data Security & Information Lifecycle ","name":"DSI-03","value":0,"passAssetCnt":0,"totalAssetCnt":4,"layer":"third","reqnum":5},{"id":"DSI-05","parent":"Data Security & Information Lifecycle ","name":"DSI-05","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":5},{"id":"DSI-06","parent":"Data Security & Information Lifecycle ","name":"DSI-06","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":5},{"id":"DSI-07","parent":"Data Security & Information Lifecycle ","name":"DSI-07","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":5},{"id":"DCS-01","parent":"Datacenter Security","name":"DCS-01","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-02","parent":"Datacenter Security","name":"DCS-02","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-03","parent":"Datacenter Security","name":"DCS-03","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-04","parent":"Datacenter Security","name":"DCS-04","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-05","parent":"Datacenter Security","name":"DCS-05","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-06","parent":"Datacenter Security","name":"DCS-06","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-07","parent":"Datacenter Security","name":"DCS-07","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-08","parent":"Datacenter Security","name":"DCS-08","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-09","parent":"Datacenter Security","name":"DCS-09","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"EKM-01","parent":"Encryption & Key Management","name":"EKM-01","value":51,"passAssetCnt":34,"totalAssetCnt":67,"layer":"third","reqnum":7},{"id":"EKM-02","parent":"Encryption & Key Management","name":"EKM-02","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":7},{"id":"EKM-03","parent":"Encryption & Key Management","name":"EKM-03","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":7},{"id":"EKM-04","parent":"Encryption & Key Management","name":"EKM-04","value":25,"passAssetCnt":9,"totalAssetCnt":36,"layer":"third","reqnum":7},{"id":"GRM-03","parent":"Governance and Risk Management\r\n","name":"GRM-03","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"GRM-04","parent":"Governance and Risk Management\r\n","name":"GRM-04","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"GRM-05","parent":"Governance and Risk Management\r\n","name":"GRM-05","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"GRM-07","parent":"Governance and Risk Management\r\n","name":"GRM-07","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"GRM-08","parent":"Governance and Risk Management\r\n","name":"GRM-08","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"GRM-09","parent":"Governance and Risk Management\r\n","name":"GRM-09","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"GRM-10","parent":"Governance and Risk Management\r\n","name":"GRM-10","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"HRS-01","parent":"Human Resources","name":"HRS-01","value":55,"passAssetCnt":40,"totalAssetCnt":73,"layer":"third","reqnum":9},{"id":"HRS-07","parent":"Human Resources","name":"HRS-07","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":9},{"id":"HRS-08","parent":"Human Resources","name":"HRS-08","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":9},{"id":"HRS-11","parent":"Human Resources","name":"HRS-11","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":9},{"id":"IAM-01","parent":"Identity & Access Management\r\n","name":"IAM-01","value":41,"passAssetCnt":14,"totalAssetCnt":34,"layer":"third","reqnum":10},{"id":"IAM-02","parent":"Identity & Access Management\r\n","name":"IAM-02","value":63,"passAssetCnt":24,"totalAssetCnt":38,"layer":"third","reqnum":10},{"id":"IAM-03","parent":"Identity & Access Management\r\n","name":"IAM-03","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":10},{"id":"IAM-04","parent":"Identity & Access Management\r\n","name":"IAM-04","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":10},{"id":"IAM-05","parent":"Identity & Access Management\r\n","name":"IAM-05","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":10},{"id":"IAM-08","parent":"Identity & Access Management\r\n","name":"IAM-08","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":10},{"id":"IAM-11","parent":"Identity & Access Management\r\n","name":"IAM-11","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":10},{"id":"ISV-01","parent":"Infrastructure & Virtualization Security","name":"ISV-01","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"ISV-02","parent":"Infrastructure & Virtualization Security","name":"ISV-02","value":44,"passAssetCnt":121,"totalAssetCnt":274,"layer":"third","reqnum":11},{"id":"ISV-04","parent":"Infrastructure & Virtualization Security","name":"ISV-04","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"ISV-05","parent":"Infrastructure & Virtualization Security","name":"ISV-05","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"ISV-06","parent":"Infrastructure & Virtualization Security","name":"ISV-06","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"ISV-07","parent":"Infrastructure & Virtualization Security","name":"ISV-07","value":100,"passAssetCnt":1,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"ISV-08","parent":"Infrastructure & Virtualization Security","name":"ISV-08","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"ISV-12","parent":"Infrastructure & Virtualization Security","name":"ISV-12","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"STA-01","parent":"Supply Chain Management, Transparency, and Accountability\r\n","name":"STA-01","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":14},{"id":"TEV-01","parent":"Threat and Vulnerability Management","name":"TEV-01","value":100,"passAssetCnt":1,"totalAssetCnt":1,"layer":"third","reqnum":15},{"id":"TEV-02","parent":"Threat and Vulnerability Management","name":"TEV-02","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":15}];


formatter: function(data) {


let modifiedData = this.data.filter(
val => {
return val.layer == 'third';
}
);
// let modified = [];
for (let i = 0; i < modifiedData.length; i++) {
const modified = modifiedData.filter(val => {
return val.reqnum == modifiedData[i].reqnum;
});
const passAssetCnt = modified.reduce(
(prev, cur) => prev + cur.passAssetCnt,
0
);
console.log(passAssetCnt);
const totalAssetCnt = modified.reduce(
(prev, cur) => prev + cur.totalAssetCnt,
0
);
console.log(totalAssetCnt);

// console.log((passAssetCnt / totalAssetCnt) * 100);
const percent = (passAssetCnt / totalAssetCnt) * 100;
console.log(percent);
// return this.point.name + '<br>' + Math.round(percent) + '%';




}
}

最佳答案

终于能够通过重新创建数组然后再次与每个点进行比较来解决这个问题。

 var res =   this.point.series.userOptions.data.reduce((acc, obj)=>{
var existItem = acc.find(item => item.reqnum === obj.reqnum);
if(existItem){
existItem.passAssetCnt += obj.passAssetCnt;
existItem.totalAssetCnt += obj.totalAssetCnt;
return acc;
}
acc.push(obj);
return acc;
}, []);



var j;
for (j = 0; j < res.length; j++) {
if(res[j].name == this.point.name) {
console.log(this.point.name + '<br>' + Math.round(res[j].passAssetCnt/res[j].totalAssetCnt*100) + '%');
return this.point.name + '<br>' + Math.round(res[j].passAssetCnt/res[j].totalAssetCnt*100) + '%';
}
}

关于javascript - highchart 旭日百分比,不是相对百分比,而是取决于其他属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53468244/

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