使用具有多索引的数据加载D3 JSON(来自Python多索引系列)

时间:2017-09-12 10:27:50

标签: javascript json d3.js

如何使用以下内容生成一组雷达图表(每个商店/部门/角色组合一个)?

我正在讨厌的javascript代码是:

var radars = d3.json("{% url 'API_fetch_month' id=store.id %}", function(error, data) {
    if (error) throw error;

    alert(JSON.parse(JSON.stringify(data )));
    today=new Date();

    var elements = data.filter(function(d) {
                    if (d[0]==today) {return d} 
                })
                .map(function (e,i) {
                    return {
                        Store: i[0],
                        Department: i[1],
                        Role: i[2],
                        Value: e.value
                    };
                })
    });

...并且上面的alert(JSON.parse(JSON.stringify(data )));返回以下结构:

{"1514160000000":{
                 "["New York","Electronics","A","Junior"]":-0.56489166
                ,"["New York","Electronics","A","Senior"]":0.3708967542
                ,"["New York","Electronics","B","Junior"]":0.1624985591
                ,"["New York","Household","B","Junior"]":-0.5320542944
                ,"["New York","Household","B","Senior"]":1.2438264269
                ,"["Paris","Electronics","B","Junior"]":0.7407341691
                ,"["Paris","Electronics","B","Senior"]":1.2866767014
                ,"["Paris","Household","B","Senior"]":-1.0081989481
                ,"["Paris","Household","C","Junior"]":0.0623007
                ,"["Paris","Household","C","Senior"]":0.2202688673
                }
,"1514246400000":{
                 "["New York","Electronics","A","Junior"]":-0.0438995686
                ,"["New York","Electronics","A","Senior"]":-1.1787308977
                ,"["New York","Electronics","B","Junior"]":0.1803050415
                ,"["New York","Electronics","B","Senior"]":0.9896253858
                ,"["New York","Electronics","C","Junior"]":-0.9389344253
                }
,...etc...
}

0 个答案:

没有答案