2015-12-02 62 views
0

我使用的是d3.js圖,它是依賴於貌似數據:d3.js圖形數據屬性的情況下靈敏

var graph = { 
             "nodes" : [{"name" : "Appointments"},{"name" : "Store Visit"},{"name" : "Visit History"},{"name" : "Resume Store Visit"}], 
             "links" : [{"source":"Store Visit","target":"Appointments","value":6}, 
               {"source":"Appointments","target":"Visit History","value":7}, 
               {"source":"Visit History","target":"Store Visit","value":2}, 
               {"source":"Resume Store Visit","target":"Visit History","value":1}, 
               {"source":"Appointments","target":"Resume Store Visit","value":5}] 
               }; 

我的REST服務返回完全相同的數據,但屬性名稱來源,目標和價值(注意第一個字母大寫)

此錯誤打破它

Uncaught TypeError: Cannot read property 'weight' of undefinedl.start @ d3.v3.min.js:4(anonymous function) @ userflowd3.html:64(anonymous function) @ d3.v3.min.js:1t @ d3.v3.min.js:1u @ d3.v3.min.js:1 

那麼,這將是對JSON返回data.items替換屬性值低的方式呃情況?

回答

0

,所以我不得不這樣做 像

var gLinks = JSON.stringify(data.items); 
             gLinks = gLinks.replace(/Source/g,'source'); 
             gLinks = gLinks.replace(/Target/g,'target'); 
             gLinks = gLinks.replace(/Value/g,'value'); 
             var arr = JSON.parse(gLinks); 
相關問題