Hi I am new to Kendo UI. This is great I like it. I have a problem. I have the data in the following format:
var data = [{ "Region": "Pakistan", "OS": "Windows", "Rank": 1, "TotalUsers": 265 },
{ "Region": "United States", "OS": "IPhone", "Rank": 1, "TotalUsers": 145 },
{ "Region": "United States", "OS": "Android", "Rank": 1, "TotalUsers": 125 },
{ "Region": "India", "OS": "Android", "Rank": 1, "TotalUsers": 32 }
];
I want to show the "Region" wise data. Like, in which region (Region), which operating system(OS) is used by how many users (TotalUsers). I referred to the following article to solve this problem, but all in vain.
http://www.kendoui.com/forums/ui/chart/multiple-series-in-datasource-dynamic.aspx
Below is my complete code:
$(document).ready(function () {
//Note that there may be as many regions as there are countries in the world. So I need to add the chart series dynamically.
var data = [{ "Region": "Pakistan", "OS": "Windows", "Rank": 1, "TotalUsers": 265 },
{ "Region": "United States", "OS": "IPhone", "Rank": 1, "TotalUsers": 145 },
{ "Region": "United States", "OS": "Android", "Rank": 1, "TotalUsers": 125 },
{ "Region": "India", "OS": "Android", "Rank": 1, "TotalUsers": 32 }
];
var dataSource = new kendo.data.DataSource({
data: data,
group: {
field: "Region",
dir: "asc"
}
});
dataSource.read();
var view = dataSource.view();
var chartSeries = [];
for (var groupIx = 0; groupIx < view.length; groupIx++) {
var group = view[groupIx];
chartSeries.push({
field: "TotalUsers",
name: group.value
});
}
$("#chart").kendoChart({
theme: $(document).data("kendoSkin") || "default",
transitions: true,
title: {
text: "My Chart Title"
},
seriesDefaults: {
type: "column",
stack: true
},
dataSource: data,
series: chartSeries,
tooltip: {
visible: true,
format: "{0}"
},
categoryAxis: {
field: "OS",
labels: {
rotation: 45
}
}
});
});
Attached is an example of the desired chart.
var data = [{ "Region": "Pakistan", "OS": "Windows", "Rank": 1, "TotalUsers": 265 },
{ "Region": "United States", "OS": "IPhone", "Rank": 1, "TotalUsers": 145 },
{ "Region": "United States", "OS": "Android", "Rank": 1, "TotalUsers": 125 },
{ "Region": "India", "OS": "Android", "Rank": 1, "TotalUsers": 32 }
];
I want to show the "Region" wise data. Like, in which region (Region), which operating system(OS) is used by how many users (TotalUsers). I referred to the following article to solve this problem, but all in vain.
http://www.kendoui.com/forums/ui/chart/multiple-series-in-datasource-dynamic.aspx
Below is my complete code:
$(document).ready(function () {
//Note that there may be as many regions as there are countries in the world. So I need to add the chart series dynamically.
var data = [{ "Region": "Pakistan", "OS": "Windows", "Rank": 1, "TotalUsers": 265 },
{ "Region": "United States", "OS": "IPhone", "Rank": 1, "TotalUsers": 145 },
{ "Region": "United States", "OS": "Android", "Rank": 1, "TotalUsers": 125 },
{ "Region": "India", "OS": "Android", "Rank": 1, "TotalUsers": 32 }
];
var dataSource = new kendo.data.DataSource({
data: data,
group: {
field: "Region",
dir: "asc"
}
});
dataSource.read();
var view = dataSource.view();
var chartSeries = [];
for (var groupIx = 0; groupIx < view.length; groupIx++) {
var group = view[groupIx];
chartSeries.push({
field: "TotalUsers",
name: group.value
});
}
$("#chart").kendoChart({
theme: $(document).data("kendoSkin") || "default",
transitions: true,
title: {
text: "My Chart Title"
},
seriesDefaults: {
type: "column",
stack: true
},
dataSource: data,
series: chartSeries,
tooltip: {
visible: true,
format: "{0}"
},
categoryAxis: {
field: "OS",
labels: {
rotation: 45
}
}
});
});
Attached is an example of the desired chart.