<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script><script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.min.js"></script><script type="text/javascript">
google.charts.setOnLoadCallback(NumberOfUsersPerRegion);
function NumberOfUsersPerRegion () {
var dataCharts = new google.visualization.DataTable();
dataCharts.addColumn('string', 'Category');
dataCharts.addColumn('number', 'User Count');
var requestUri = _spPageContextInfo.webAbsoluteUrl +"/_api/Web/Lists/getByTitle('NPT Tickets')/items?$select=Loc,Category,Ticket_x0020_By/Title&$Expand=Ticket_x0020_By/Title";
// execute AJAX request
$.ajax({
url: requestUri,
type: "GET",
async:false,
headers: { "ACCEPT": "application/json;odata=verbose" },
success: function (data) {
console.log(data);
var dataResults = data.d.results;
var Regions;
var timelost;
var addTimeLost = 0;
var Users;
for (i=0; i< data.d.results.length; i++) {
Timelost = dataResults[i].Time_x0020_Lost;
Location = dataResults[i].Loc;
Users = dataResults[i].Ticket_x0020_By.Title;
console.log(Users);
dataCharts.addRow([Category , Users]);
}
},
});
console.log(dataCharts);
var newData = google.visualization.data.group(dataCharts, [{
column: 0,
label: 'Location',
type: 'string'
}], [{
column: 1,
label: 'Number of users',
aggregation: google.visualization.data.count,
type: 'number'
}]);
var options = {'title':'Cummulative Time Lost in All Locations',
'width':700,
'height':500};
var chart = new google.visualization.PieChart(document.getElementById('NumberOfUsersPerRegion'));
console.log(newData);
chart.draw(newData, options);
}//end of function NumberOfUsersPerRegion
</script><div id="NumberOfUsersPerRegion" style="width:700px;height: 800px;float:left ;margin:0 auto;display:block"></div>Wandering if i could get any help to figure why my code throws this error "Type mismatch. Value USERSNAME does not match type number in column index 1(…)". i'm trying to count the number of users who belong to a cetain category that have added
an item to the list. The DataCharts Table array should contain all the categories and the corresponding users. which i then pass to the aggregating function to group the table per category and then count the users.
the Count is expecting a Number to be passed which i think is wrong, it should accept all types and then return a Number.
The Second Question is how can i remove duplicate names from appearing in the dataCharts table.(Because a user can add multiple items to a single category). i would like to remove the duplicates before aggregation.
thanks
Please let me know if i didnt describe the problem correctly. i can elaborate further