如何从此json文件绘制饼图。 d3js或Google图表

时间:2019-05-02 12:32:23

标签: json d3.js

嘿,我有一个非常复杂的json文件,我想从中绘制一个饼图,但只包含一些特定数据

{ 
    "test_list":
        "STORE-006-TC8", 
        "STORE-009-TC1", 
        "STORE-009-TC2", 
        "STORE-009-TC3", 
        "STORE-010-TC1", 
        "STORE-011-TC1", 
        "SYSTEM-020-TC1", 
        "SYSTEM-020-TC2", 
        "TLS-001-TC1", 
        "TLS-001-TC2", 
        "TLS-001-TC3", 
        "TLS-001-TC4", 
        "TLS-001-TC5", 
        "TLS-001-TC6", 
        "VIDEO-002-TC3", 
        "VIDEO-003-TC12", 
        "VIDEO-003-TC9", 
        "VIDEO-AAR-001-TC1", 
        "X1CRYPTO-001-TC1", 
        "X1CRYPTO-001-TC2", 
        "X1CRYPTO-001-TC3", 
        "X1CRYPTO-001-TC4", 
        "X1CRYPTO-001-TC5", 
        "X1CRYPTO-001-TC6"
    ], 
    "result": {
        "192.168.1.113": {
            "nb_tests": 201, 
            "nb_passed": 101, 
            "nb_failed": 49, 
            "nb_other": 51, 
            "passed": [
                "DPI-008-TC3", 
                "AUDIO-013-TC2", 
                "VIDEO-002-TC3", 
                "IMG-004-TC1", 
                "X1CRYPTO-001-TC4", 
                "SEC-906-TC11", 
                "DPI-012-TC1", 
                "SCREENSAVER-001-TC0", 
                "STORE-006-TC8", 
                "FONT-007-TC5", 
                "X1CRYPTO-001-TC6", 
                "DLSHADERS-001-TC15", 
                "DPI-HDROUT-TC1", 
                "DLSHADERS-001-TC5", 
                "SEC-403-TC1", 
                "SEC-910-TC3", 
                "SEC-404-TC1", 
                "SEC-905-TC1", 
                "PLAY-259-TC1", 
                "FONT-014-TC8", 
                "SEC-910-TC2", 
                "SCALE-001-TC1", 
                "SEC-401-TC1", 
                "AUDIO-004-TC1", 
                "SSL-001-TC1", 
                "STORE-005-TC1", 
                "PERF-006-TC1", 
                "FONT-013-TC1", 
                "EFFECT-001-TC1", 
                "EDPI-001-TC1", 
                "DLSHADERS-001-TC24", 
                "CONF-001-TC4", 
                "DLSHADERS-001-TC25", 
                "DLSHADERS-001-TC2", 
                "EFFECT-006-TC1", 
                "FONT-005-TC1", 
                "STORE-009-TC1", 
                "CONF-001-TC5", 
                "STORE-010-TC1", 
                "IMG-001-TC1", 
                "EFFECT-003-TC1", 
                "DLSHADERS-001-TC1", 
                "SAND-DPI-TC0", 
                "MEMORY-002-TC2", 
                "DPI-004-TC3", 
                "DPI-013-TC1", 
                "STORE-009-TC3", 
                "DPI-009-TC1", 
                "DLSHADERS-001-TC23", 
                "FONT-014-TC2", 
                "CRYPTO-002-TC1", 
                "BLEND-001-TC1", 
                "X1CRYPTO-001-TC2", 
                "VIDEO-003-TC12", 
                "AUDIO-001-TC1", 
                "FONT-004-TC1", 
                "X1CRYPTO-001-TC5", 
                "ALWAYS-FRESH-001-TC0", 
                "FONT-007-TC3", 
                "DLSHADERS-001-TC7", 
                "DPI-400-TC1", 
                "STORE-006-TC10", 
                "AUDIO-001-TC7", 
                "EFFECT-002-TC1", 
                "DLSHADERS-001-TC12", 
                "CONF-001-TC3", 
                "FONT-014-TC11", 
                "DPI-001-TC3", 
                "DPI-008-TC4", 
                "MDX-002-TC1", 
                "SSL-001-TC2", 
                "FONT-011-TC1", 
                "DLSHADERS-001-TC9", 
                "EFFECT-004-TC1", 
                "DLSHADERS-001-TC20", 
                "X1CRYPTO-001-TC1", 
                "DLSHADERS-001-TC10", 
                "FONT-002-TC1", 
                "PLAY-100-TC3", 
                "AUDIO-001-TC4", 
                "X1CRYPTO-001-TC3", 
                "AUDIO-004-TC2", 
                "MEMORY-001-TC1", 
                "FONT-015-TC1", 
                "VIDEO-AAR-001-TC1", 
                "STORE-009-TC2", 
                "VIDEO-003-TC9", 
                "IPV6-001-TC6", 
                "FONT-014-TC5", 
                "DPI-008-TC5", 
                "FONT-014-TC17", 
                "DLSHADERS-001-TC4", 
                "FONT-007-TC1", 
                "CRYPTO-001-TC1", 
                "DLSHADERS-001-TC3", 
                "FONT-014-TC7", 
                "INPUT-001-TC5", 
                "DLSHADERS-001-TC26", 
                "DLSHADERS-001-TC17", 
                "IMG-005-TC1", 
                "FONT-007-TC4"
            ], 
            "failed": [
                "AUDIO-025-TC12", 
                "AUDIO-024-TC4", 
                "FONT-014-TC4", 
                "IPV6-001-TC2", 
                "FONT-001-TC1", 
                "AUDIO-025-TC20", 
                "PROF-001-TC15", 
                "REND-005-TC5", 
                "NETWORK-009-TC1", 
                "AUDIO-025-TC10", 
                "FORMAT-NOTIFY-TC3", 
                "AUDIO-025-TC9", 
                "PROF-001-TC19", 
                "REND-005-TC3", 
                "FONT-010-TC1", 
                "AUDIO-025-TC13", 
                "AUDIO-025-TC21", 
                "PROF-001-TC16", 
                "PLAY-UNDERFLOW-TC1", 
                "SYSTEM-020-TC2", 
                "IPV6-001-TC3", 
                "IMG-002-TC1", 
                "FONT-014-TC9", 
                "AUDIO-025-TC8", 
                "AUDIO-025-TC18", 
                "SEC-906-TC5", 
                "PROF-001-TC17", 
                "FONT-014-TC13", 
                "SEC-906-TC6", 
                "AUDIO-025-TC2", 
                "AUDIO-024-TC1", 
                "AUDIO-025-TC14", 
                "STORE-006-TC3", 
                "IPV6-001-TC4", 
                "AUDIO-024-TC9", 
                "CLOCK-DPI-TC1", 
                "AUDIO-025-TC7", 
                "AUDIO-025-TC4", 
                "SYSTEM-020-TC1", 
                "REND-005-TC2", 
                "AUDIO-025-TC5", 
                "AUDIO-024-TC6", 
                "CONF-001-TC1", 
                "SEC-900-TC2", 
                "PROF-001-TC14", 
                "PROF-001-TC10", 
                "PROF-001-TC9", 
                "AUDIO-025-TC19", 
                "DLSHADERS-001-TC6"
            ], 
            "other": [
                "SSL-001-TC3", 
                "TLS-001-TC4", 
                "SEC-908-TC6", 
                "STORE-011-TC1", 
                "SSL-001-TC14", 
                "SSL-001-TC6", 
                "SEC-900-TC1", 
                "DRM-009-TC14", 
                "SEC-906-TC22", 
                "TLS-001-TC5", 
                "ACT-004-TC11", 
                "CRYPTO-005-TC1", 
                "SSL-001-TC13", 
                "CRYPTO-003-TC1", 
                "SEC-908-TC9", 
                "TLS-001-TC6", 
                "SEC-908-TC10", 
                "CRYPTO-005-TC2", 
                "TLS-001-TC2", 
                "SSL-001-TC12", 
                "SSL-001-TC8", 
                "SSL-001-TC16", 
                "SEC-908-TC4", 
                "FONT-014-TC1", 
                "SEC-908-TC1", 
                "SEC-908-TC11", 
                "SSL-001-TC11", 
                "SSL-001-TC10", 
                "SEC-907-TC1", 
                "DRM-007-TC4", 
                "REND-005-TC1", 
                "CRYPTO-005-TC4", 
                "TLS-001-TC1", 
                "SEC-908-TC7", 
                "FONT-014-TC3", 
                "SEC-906-TC21", 
                "SEC-907-TC3", 
                "SEC-908-TC8", 
                "CRYPTO-005-TC3", 
                "SSL-001-TC5", 
                "SEC-908-TC3", 
                "SEC-908-TC12", 
                "FONT-014-TC19", 
                "TLS-001-TC3", 
                "SSL-001-TC4", 
                "SEC-908-TC5", 
                "SSL-001-TC7", 
                "SEC-907-TC2", 
                "DRM-009-TC16", 
                "DRM-007-TC3", 
                "DRM-009-TC13"
            ]
        }, 
        "192.168.1.132": {
            "nb_tests": 202, 
            "nb_passed": 100, 
            "nb_failed": 52, 
            "nb_other": 50, 
            "passed": [
                "DPI-008-TC3", 
                "MEMORY-002-TC1", 
                "AUDIO-013-TC2", 
                "VIDEO-002-TC3", 
                "FONT-014-TC4", 
                "IMG-004-TC1", 
                "X1CRYPTO-001-TC4", 
                "SEC-906-TC11", 
                "DPI-012-TC1", 
                "FONT-001-TC1", 
                "SCREENSAVER-001-TC0", 
                "STORE-006-TC8", 
                "FONT-007-TC5", 
                "X1CRYPTO-001-TC6", 
                "DLSHADERS-001-TC15", 
                "DPI-HDROUT-TC1", 
                "DLSHADERS-001-TC5", 
                "SEC-403-TC1", 
                "SEC-910-TC3", 
                "SEC-404-TC1", 
                "SEC-905-TC1", 
                "PLAY-259-TC1", 
                "FONT-014-TC8", 
                "SEC-910-TC2", 
                "SCALE-001-TC1", 
                "SEC-401-TC1", 
                "AUDIO-004-TC1", 
                "SSL-001-TC1", 
                "STORE-005-TC1", 
                "PERF-006-TC1", 
                "FONT-013-TC1", 
                "EFFECT-001-TC1", 
                "FONT-010-TC1", 
                "EDPI-001-TC1", 
                "DLSHADERS-001-TC24", 
                "CONF-001-TC4", 
                "DLSHADERS-001-TC25", 
                "DLSHADERS-001-TC2", 
                "EFFECT-006-TC1", 
                "FONT-005-TC1", 
                "STORE-009-TC1", 
                "CONF-001-TC5", 
                "STORE-010-TC1", 
                "DLSHADERS-001-TC1", 
                "SAND-DPI-TC0", 
                "MEMORY-002-TC2", 
                "DPI-004-TC3", 
                "IMG-002-TC1", 
                "DPI-013-TC1", 
                "STORE-009-TC3", 
                "DPI-009-TC1", 
                "DLSHADERS-001-TC23", 
                "CRYPTO-002-TC1", 
                "BLEND-001-TC1", 
                "X1CRYPTO-001-TC2", 
                "VIDEO-003-TC12", 
                "AUDIO-001-TC1", 
                "FONT-004-TC1", 
                "X1CRYPTO-001-TC5", 
                "ALWAYS-FRESH-001-TC0", 
                "FONT-007-TC3", 
                "DLSHADERS-001-TC7", 
                "DPI-400-TC1", 
                "STORE-006-TC10", 
                "AUDIO-001-TC7", 
                "IPV6-001-TC4", 
                "DLSHADERS-001-TC12", 
                "CONF-001-TC3", 
                "DPI-001-TC3", 
                "DPI-008-TC4", 
                "MDX-002-TC1", 
                "SSL-001-TC2", 
                "DLSHADERS-001-TC9", 
                "EFFECT-004-TC1", 
                "DLSHADERS-001-TC20", 
                "X1CRYPTO-001-TC1", 
                "DLSHADERS-001-TC10", 
                "FONT-002-TC1", 
                "PLAY-100-TC3", 
                "AUDIO-001-TC4", 
                "X1CRYPTO-001-TC3", 
                "AUDIO-004-TC2", 
                "MEMORY-001-TC1", 
                "VIDEO-AAR-001-TC1", 
                "STORE-009-TC2", 
                "VIDEO-003-TC9", 
                "IPV6-001-TC6", 
                "FONT-014-TC5", 
                "DPI-008-TC5", 
                "FONT-014-TC17", 
                "DLSHADERS-001-TC4", 
                "FONT-007-TC1", 
                "CRYPTO-001-TC1", 
                "DLSHADERS-001-TC3", 
                "FONT-014-TC7", 
                "INPUT-001-TC5", 
                "DLSHADERS-001-TC26", 
                "DLSHADERS-001-TC17", 
                "DLSHADERS-001-TC6", 
                "FONT-007-TC4"
            ], 
            "failed": [
                "AUDIO-025-TC12", 
                "AUDIO-024-TC4", 
                "IPV6-001-TC2", 
                "AUDIO-025-TC20", 
                "PROF-001-TC15", 
                "REND-005-TC5", 
                "NETWORK-009-TC1", 
                "AUDIO-025-TC10", 
                "FORMAT-NOTIFY-TC3", 
                "AUDIO-025-TC9", 
                "PROF-001-TC19", 
                "REND-005-TC3", 
                "AUDIO-025-TC13", 
                "AUDIO-025-TC21", 
                "PROF-001-TC16", 
                "IMG-001-TC1", 
                "PLAY-UNDERFLOW-TC1", 
                "EFFECT-003-TC1", 
                "SYSTEM-020-TC2", 
                "IPV6-001-TC3", 
                "FONT-014-TC2", 
                "FONT-014-TC9", 
                "AUDIO-025-TC8", 
                "AUDIO-025-TC18", 
                "SEC-906-TC5", 
                "PROF-001-TC17", 
                "FONT-014-TC13", 
                "SEC-906-TC6", 
                "AUDIO-025-TC2", 
                "AUDIO-024-TC1", 
                "AUDIO-025-TC14", 
                "STORE-006-TC3", 
                "EFFECT-002-TC1", 
                "FONT-014-TC19", 
                "FONT-014-TC11", 
                "AUDIO-024-TC9", 
                "CLOCK-DPI-TC1", 
                "AUDIO-025-TC7", 
                "AUDIO-025-TC4", 
                "SYSTEM-020-TC1", 
                "FONT-011-TC1", 
                "REND-005-TC2", 
                "AUDIO-025-TC5", 
                "AUDIO-024-TC6", 
                "CONF-001-TC1", 
                "SEC-900-TC2", 
                "FONT-015-TC1", 
                "PROF-001-TC14", 
                "PROF-001-TC10", 
                "PROF-001-TC9", 
                "IMG-005-TC1", 
                "AUDIO-025-TC19"
            ], 
            "other": [
                "SSL-001-TC3", 
                "TLS-001-TC4", 
                "SEC-908-TC6", 
                "STORE-011-TC1", 
                "SSL-001-TC14", 
                "SSL-001-TC6", 
                "SEC-900-TC1", 
                "DRM-009-TC14", 
                "SEC-906-TC22", 
                "TLS-001-TC5", 
                "ACT-004-TC11", 
                "CRYPTO-005-TC1", 
                "SSL-001-TC13", 
                "CRYPTO-003-TC1", 
                "SEC-908-TC9", 
                "TLS-001-TC6", 
                "SEC-908-TC10", 
                "CRYPTO-005-TC2", 
                "TLS-001-TC2", 
                "SSL-001-TC12", 
                "SSL-001-TC8", 
                "SSL-001-TC16", 
                "SEC-908-TC4", 
                "FONT-014-TC1", 
                "SEC-908-TC1", 
                "SEC-908-TC11", 
                "SSL-001-TC11", 
                "SSL-001-TC10", 
                "SEC-907-TC1", 
                "DRM-007-TC4", 
                "REND-005-TC1", 
                "CRYPTO-005-TC4", 
                "TLS-001-TC1", 
                "SEC-908-TC7", 
                "FONT-014-TC3", 
                "SEC-906-TC21", 
                "SEC-907-TC3", 
                "SEC-908-TC8", 
                "CRYPTO-005-TC3", 
                "SSL-001-TC5", 
                "SEC-908-TC3", 
                "SEC-908-TC12", 
                "TLS-001-TC3", 
                "SSL-001-TC4", 
                "SEC-908-TC5", 
                "SSL-001-TC7", 
                "SEC-907-TC2", 
                "DRM-009-TC16", 
                "DRM-007-TC3", 
                "DRM-009-TC13"
            ]
        }, 
        "192.168.1.140": {
            "nb_tests": 202, 
            "nb_passed": 0, 
            "nb_failed": 0, 
            "nb_other": 202, 
            "passed": [], 
            "failed": [], 
            "other": [
                "DPI-008-TC3", 
                "AUDIO-025-TC12", 
                "AUDIO-024-TC4", 
                "MEMORY-002-TC1", 
                "AUDIO-013-TC2", 
                "VIDEO-002-TC3", 
                "FONT-014-TC4", 
                "IMG-004-TC1", 
                "X1CRYPTO-001-TC4", 
                "SEC-906-TC11", 
                "DPI-012-TC1", 
                "SSL-001-TC3", 
                "IPV6-001-TC2", 
                "TLS-001-TC4", 
                "FONT-001-TC1", 
                "SEC-908-TC6", 
                "SCREENSAVER-001-TC0", 
                "STORE-006-TC8", 
                "FONT-007-TC5", 
                "AUDIO-025-TC20", 
                "X1CRYPTO-001-TC6", 
                "DLSHADERS-001-TC15", 
                "DPI-HDROUT-TC1", 
                "STORE-011-TC1", 
                "DLSHADERS-001-TC5", 
                "SEC-403-TC1", 
                "SSL-001-TC14", 
                "SSL-001-TC6", 
                "SEC-900-TC1", 
                "DRM-009-TC14", 
                "SEC-910-TC3", 
                "SEC-404-TC1", 
                "SEC-906-TC22", 
                "SEC-905-TC1", 
                "PROF-001-TC15", 
                "TLS-001-TC5", 
                "PLAY-259-TC1", 
                "FONT-014-TC8", 
                "SEC-910-TC2", 
                "ACT-004-TC11", 
                "CRYPTO-005-TC1", 
                "SSL-001-TC13", 
                "SCALE-001-TC1", 
                "CRYPTO-003-TC1", 
                "SEC-401-TC1", 
                "REND-005-TC5", 
                "AUDIO-004-TC1", 
                "SEC-908-TC9", 
                "TLS-001-TC6", 
                "NETWORK-009-TC1", 
                "AUDIO-025-TC10", 
                "SSL-001-TC1", 
                "STORE-005-TC1", 
                "FORMAT-NOTIFY-TC3", 
                "AUDIO-025-TC9", 
                "SEC-908-TC10", 
                "PERF-006-TC1", 
                "FONT-013-TC1", 
                "PROF-001-TC19", 
                "CRYPTO-005-TC2", 
                "EFFECT-001-TC1", 
                "TLS-001-TC2", 
                "REND-005-TC3", 
                "SSL-001-TC12", 
                "SSL-001-TC8", 
                "SSL-001-TC16", 
                "FONT-010-TC1", 
                "EDPI-001-TC1", 
                "SEC-908-TC4", 
                "DLSHADERS-001-TC24", 
                "CONF-001-TC4", 
                "DLSHADERS-001-TC25", 
                "FONT-014-TC1", 
                "AUDIO-025-TC13", 
                "SEC-908-TC1", 
                "DLSHADERS-001-TC2", 
                "EFFECT-006-TC1", 
                "AUDIO-025-TC21", 
                "SEC-908-TC11", 
                "SSL-001-TC11", 
                "SSL-001-TC10", 
                "SEC-907-TC1", 
                "FONT-005-TC1", 
                "DRM-007-TC4", 
                "STORE-009-TC1", 
                "REND-005-TC1", 
                "CRYPTO-005-TC4", 
                "CONF-001-TC5", 
                "STORE-010-TC1", 
                "PROF-001-TC16", 
                "IMG-001-TC1", 
                "PLAY-UNDERFLOW-TC1", 
                "TLS-001-TC1", 
                "EFFECT-003-TC1", 
                "SYSTEM-020-TC2", 
                "IPV6-001-TC3", 
                "DLSHADERS-001-TC1", 
                "SAND-DPI-TC0", 
                "MEMORY-002-TC2", 
                "SEC-908-TC7", 
                "DPI-004-TC3", 
                "IMG-002-TC1", 
                "DPI-013-TC1", 
                "STORE-009-TC3", 
                "FONT-014-TC3", 
                "DPI-009-TC1", 
                "DLSHADERS-001-TC23", 
                "SEC-906-TC21", 
                "FONT-014-TC2", 
                "CRYPTO-002-TC1", 
                "SEC-907-TC3", 
                "SEC-908-TC8", 
                "CRYPTO-005-TC3", 
                "SSL-001-TC5", 
                "BLEND-001-TC1", 
                "FONT-014-TC9", 
                "AUDIO-025-TC8", 
                "AUDIO-025-TC18", 
                "X1CRYPTO-001-TC2", 
                "VIDEO-003-TC12", 
                "AUDIO-001-TC1", 
                "SEC-906-TC5", 
                "FONT-004-TC1", 
                "X1CRYPTO-001-TC5", 
                "ALWAYS-FRESH-001-TC0", 
                "FONT-007-TC3", 
                "PROF-001-TC17", 
                "DLSHADERS-001-TC7", 
                "FONT-014-TC13", 
                "SEC-906-TC6", 
                "AUDIO-025-TC2", 
                "DPI-400-TC1", 
                "SEC-908-TC3", 
                "STORE-006-TC10", 
                "AUDIO-024-TC1", 
                "AUDIO-001-TC7", 
                "AUDIO-025-TC14", 
                "STORE-006-TC3", 
                "IPV6-001-TC4", 
                "EFFECT-002-TC1", 
                "DLSHADERS-001-TC12", 
                "SEC-908-TC12", 
                "CONF-001-TC3", 
                "FONT-014-TC19", 
                "FONT-014-TC11", 
                "TLS-001-TC3", 
                "DPI-001-TC3", 
                "SSL-001-TC4", 
                "AUDIO-024-TC9", 
                "SEC-908-TC5", 
                "DPI-008-TC4", 
                "CLOCK-DPI-TC1", 
                "AUDIO-025-TC7", 
                "AUDIO-025-TC4", 
                "MDX-002-TC1", 
                "SYSTEM-020-TC1", 
                "SSL-001-TC7", 
                "SSL-001-TC2", 
                "SEC-907-TC2", 
                "FONT-011-TC1", 
                "DRM-009-TC16", 
                "REND-005-TC2", 
                "DLSHADERS-001-TC9", 
                "AUDIO-025-TC5", 
                "AUDIO-024-TC6", 
                "CONF-001-TC1", 
                "EFFECT-004-TC1", 
                "DLSHADERS-001-TC20", 
                "X1CRYPTO-001-TC1", 
                "DLSHADERS-001-TC10", 
                "SEC-900-TC2", 
                "FONT-002-TC1", 
                "PLAY-100-TC3", 
                "AUDIO-001-TC4", 
                "X1CRYPTO-001-TC3", 
                "DRM-007-TC3", 
                "AUDIO-004-TC2", 
                "MEMORY-001-TC1", 
            ]
        }
    }
}

所以,我只想绘制一个饼图作为信息

"192.168.1.113": {
                "nb_tests": 201, 
                "nb_passed": 101, 
                "nb_failed": 49, 
                "nb_other": 51, 

并且您可以看到,我有两台具有不同ip的机器。我想从同一个json文件中绘制两个饼图。

一个来自上述json文件的上述数据和其他饼图 为此数据

PS。我是json和d3js的新手。我已经尝试用硬编码数据绘制饼图了

像这样使用Google图表,但是上面的json文件让我难以理解。

var data = google.visualization.arrayToDataTable([
  ['Task', 'Hours per Day'],
  ['passed', 60],
  ['failed', 20],
  ['unknown status', 20]
]);

0 个答案:

没有答案