I am trying to generate a bar graph based on the count of an instance in a Project Status. The "if..." statement works beautifully, counting all elements containing the string "Complete", outputting on the console and graphing it. However, "else if..." returns nothing on the console and graphs nothing. I am dumbfounded as to what the issue might be. Any insight?
google.charts.load('current', {
'packages': ['bar']
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var complete = 0;
var deferred = 0;
var onhold = 0;
var uri = "https://company.com/sites/ITApp/_api/Web/Lists/getByTitle('Global%20Projects')/items";
$.ajax({
url: uri,
type: "GET",
async: false,
data: {},
cache: true,
headers: {
"ACCEPT": "application/json;odata=verbose"
},
success: function(data) {
var dataResults = data.d.results;
for (i = 1; i < dataResults.length; i++) {
if (dataResults[i].Project_x0020_Status == "Completed") {
complete = complete + 1;
} else if (dataResults[i].Project_x0020_Status == "Deferred") {
console.log(deferred);
deferred = deferred + 1;
} else if (dataResults[i].Project_x0020_Status == "On-Hold") {
onhold = onhold + 1;
} else {}
}
}
});
var data = google.visualization.arrayToDataTable([
['Category', 'Complete', 'Deferred', 'On-Hold'],
['Project Status', complete, deferred, onhold],
var options = {
chart: {
title: 'Company Performance',
subtitle: 'Sales, Expenses, and Profit: 2014-2017',
}
};
var chart = new google.charts.Bar(document.getElementById('columnchart_material'));
chart.draw(data, google.charts.Bar.convertOptions(options));
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="columnchart_material" style="width: 800px; height: 500px;"></div>
UPDATE: I believe this is a SharePoint issue at this point. When I go to my uri and search for "Deferred" and "On-Hold" in the XML file there, I cannot find either of them. However, when I go to the actual list containing the data on SharePoint, I can find it. Might this be an issue of the table not being translated correctly in XML after import?