0

Is it possible to create a Kendo UI DataViz chart from a remote datasource with a structure such as

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

Instead of using (from the example in the documentation)

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

I would like to use a data source formatted as

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

1 Answers1

0

Well, it's a straightforward transformation in 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}
Robert Krzyzanowski
  • 9,294
  • 28
  • 24