2014-03-30 31 views
0

是否有可能從遠程數據源創建一個劍道UI DataViz公司圖表,其結構如綁定劍道UI DataViz公司圖表系列到特定模型

"gender": [ 
     {"male": 23421}, 
     {"female": 24376}, 
     {"unknown": 324} 
     ], 

代替使用(從文檔中的示例)

<div id="chart"></div> 
<script> 
$("#chart").kendoChart({ 
    categoryAxis: { 
    field: "year" 
    }, 
    series: [ 
    { field: "value" } 
    ], 
    dataSource: [ 
    { year: "2012", value: 1 }, 
    { year: "2013", value: 2 } 
    ] 
}); 
</script> 

我想用格式化爲

<div id="chart"></div> 
<script> 
$("#chart").kendoChart({ 
    categoryAxis: { 
    field: "year" 
    }, 
    series: [ 
    { field: "value" } 
    ], 
    dataSource: [ 
    { "2012": 1 }, 
    { "2013": 2 } 
    ] 
}); 
</script> 

回答

0

WEL數據源l,這是一個簡單的Javascript轉換。

convertDataSource = function(dataSource) { 
    for(i in dataSource) { 
    (y = {})[dataSource[i].year] = dataSource[i].value; 
    dataSource[i] = y; 
    } 
    return dataSource; 
} 
convertDataSource([ { year: "2012", value: 1 }, { year: "2013", value: 2 }]) 
// [ { "2012": 1, "2013": 2}