fork download
  1. // your code goes here
  2.  
  3.  
  4. SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
  5.  
  6. // Create an instance of the current context.
  7. function sharePointReady() {
  8. clientContext = SP.ClientContext.get_current();
  9. website = clientContext.get_web();
  10.  
  11. clientContext.load(website);
  12. clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
  13. }
  14. function onRequestSucceeded() {
  15. getItemsFromView();
  16. }
  17. function onRequestFailed(sender, args) {
  18. alert('Error: ' + args.get_message());
  19. }
  20.  
  21.  
  22. var collListItem; //ListItems
  23. var chartX = []; //X-Axis Labels
  24. var chartY = []; //Y-Axis Values
  25.  
  26. var chartJs = "https://h...content-available-to-author-only...t.com/teams/CCOD/Style%20Library/ChartLibrary/Chart.min.js";
  27. var chartId = "myChart";//Chart Canvas Div
  28.  
  29. function getItemsFromView()
  30. {
  31. var listTitle="Trial";
  32. var viewTitle="All Items";
  33.  
  34. var context = new SP.ClientContext.get_current();
  35. var list = context.get_web().get_lists().getByTitle(listTitle);
  36. var view = list.get_views().getByTitle(viewTitle);
  37. context.load(view);
  38.  
  39. context.executeQueryAsync(
  40. function(sender, args) {getItemsFromList(listTitle, "<View><Query><OrderBy><FieldRef Name=Status_x0020__x0028_Calculated_x' Ascending='FALSE' /></OrderBy></Query></View>")},
  41. function(sender, args) {alert("error: " + args.get_message());}
  42. );
  43. }
  44.  
  45. function getItemsFromList(listTitle, queryText)
  46. {
  47. var context = new SP.ClientContext.get_current();
  48. var list = context.get_web().get_lists().getByTitle(listTitle);
  49.  
  50. var query = new SP.CamlQuery();
  51. query.set_viewXml(queryText);
  52.  
  53. var items = list.getItems(query);
  54.  
  55. context.load(items);
  56.  
  57. context.executeQueryAsync(
  58. function()
  59. {
  60. var listEnumerator = items.getEnumerator();
  61. var i = 0;
  62. var highestValue=0;
  63.  
  64. var statuspending = "Pending";
  65. var pendingcount = 0;
  66.  
  67. var statusOverDue = "OverDue";
  68. var OverDuecount = 0;
  69.  
  70. while (listEnumerator.moveNext())
  71. {
  72. var item=listEnumerator.get_current();
  73.  
  74.  
  75. var statusName = item.get_item("Status_x0020__x0028_Calculated_x");
  76.  
  77. if(statusName=="Pending")
  78. {
  79. pendingcount= pendingcount + 1;
  80. }else if(statusName == "Over Due")
  81. {
  82. OverDuecount = OverDuecount +1;
  83. }
  84.  
  85. i++;
  86. }
  87. chartX.push(statuspending);
  88.  
  89. chartY.push(pendingcount);
  90. highestValue = pendingcount + 10;
  91. chartX.push(statusOverDue);
  92.  
  93. chartY.push(OverDuecount);
  94.  
  95. highestValue = OverDuecount + 10;
  96.  
  97. //alert("items rtrieved: " + i);
  98. console.log("items retrieved: " + i);
  99.  
  100. //Load Chart JS
  101. loadJS(chartJs, function () {
  102.  
  103. //Generate Data
  104. var barChartData = {
  105. labels: this.chartX,
  106. datasets: [
  107. {
  108. fillColor : "rgba(0, 39, 118, 1)",
  109. strokeColor : "rgba(215, 120, 112, 1)",
  110. data: this.chartY
  111. }
  112. ]
  113. };
  114.  
  115. //Display Chart
  116. var ctx = document.getElementById(chartId).getContext("2d");
  117. var barChart = new Chart(ctx).Bar(barChartData,{
  118. scaleOverride: true,
  119. scaleSteps: 10,
  120. scaleStepWidth: 10,
  121. scaleStartValue: 0,
  122. barValueSpacing: 2,
  123. scaleShowGridLines: false,
  124. barDatasetSpacing: 1,
  125. barStrokeWidth: 1,
  126. scaleLineWidth: 1
  127. });
  128.  
  129. });
  130.  
  131. },
  132. function(sender, args) {alert("error in inner request: " + args.get_message());}
  133. );
  134.  
  135. }
  136. function loadJS(src, callback) {
  137. var s = document.createElement('script');
  138. s.src = src;
  139. s.async = true;
  140. s.onreadystatechange = s.onload = function () {
  141. var state = s.readyState;
  142. if (!callback.done && (!state || /loaded|complete/.test(state))) {
  143. callback.done = true;
  144. callback();
  145. }
  146. };
  147. document.getElementsByTagName('myChart')[0].appendChild(s);
  148. }
  149.  
Runtime error #stdin #stdout #stderr 0s 107072KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.js:4:0 ReferenceError: SP is not defined