Guest User

Untitled

a guest
Apr 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. // Declare the variables.
  2. var sitesChart = sitesChart || {};
  3.  
  4. sitesChart.Colors = ['#1BA1E2', '#E51400', '#339933','#56348E'];
  5.  
  6. sitesChart.ChartTitle =[];
  7. sitesChart.ChartT1 = [];
  8. sitesChart.ChartT2 = [];
  9. sitesChart.ChartT3= [];
  10.  
  11.  
  12. sitesChart.Desc = '';
  13.  
  14. // Override the rendering.
  15. sitesChart.FieldRenderSetup = function () {
  16. var override = {};
  17. override.Templates = {};
  18. override.Templates.Header = sitesChart.CustomHeader;
  19. override.Templates.Item = sitesChart.CustomItem;
  20. override.Templates.Footer = sitesChart.CustomFooter;
  21.  
  22. SPClientTemplates.TemplateManager.RegisterTemplateOverrides(override);
  23. };
  24.  
  25.  
  26. sitesChart.CustomItem = function (ctx) {
  27. var str = ctx.view.toString();
  28. if(ctx.view === "{3FE32257-65DA-467F-919B-16B742BA932E}"){
  29. sitesChart.ChartTitle.push(ctx.CurrentItem.Title);//columns names
  30. sitesChart.ChartT1.push(parseInt(ctx.CurrentItem.Team1));//columns names
  31. sitesChart.ChartT2.push(parseInt(ctx.CurrentItem.Team2));//columns names
  32. sitesChart.ChartT3.push(parseInt(ctx.CurrentItem.Team3));//columns names
  33. return '';
  34. }
  35.  
  36. if(ctx.view === "{31BD318D-04D3-4B78-8F50-30855F8D5B75}"){
  37. sitesChart.ChartTitle.push(ctx.CurrentItem.Title);//columns names
  38. sitesChart.ChartT1.push(parseInt(ctx.CurrentItem.Team1));//columns names
  39. sitesChart.ChartT2.push(parseInt(ctx.CurrentItem.Team2));//columns names
  40. sitesChart.ChartT3.push(parseInt(ctx.CurrentItem.Team3));//columns names
  41. return '';
  42. }
  43.  
  44. return RenderItemTemplate(ctx);
  45. }
  46.  
  47.  
  48. sitesChart.CustomHeader = function (ctx) {
  49. if(ctx.view === "{3FE32257-65DA-467F-919B-16B742BA932E}"){
  50. return "<canvas id='lineChart' width='700' height='400' style='float:left;margin-right:20px;'></canvas>";
  51. }
  52.  
  53. if(ctx.view === "{31BD318D-04D3-4B78-8F50-30855F8D5B75}"){
  54. return "<canvas id='lineChart2' width='700' height='400' style='float:left;margin-right:20px;'></canvas>";
  55. }
  56. return RenderHeaderTemplate(ctx);
  57. }
  58.  
  59. // Override the footer.
  60. sitesChart.CustomFooter = function () {
  61. if(ctx.view === "{3FE32257-65DA-467F-919B-16B742BA932E}"){
  62. var data = {
  63. labels: sitesChart.ChartTitle,
  64. datasets: [
  65. {
  66. label: "Team1",
  67. fill: false,
  68. borderColor: sitesChart.Colors[0],
  69. pointBorderColor: sitesChart.Colors[0],
  70. pointBackgroundColor: "#fff",
  71. data: sitesChart.ChartT1
  72. },
  73. {
  74. label: "Team2",
  75. fill: false,
  76. borderColor: sitesChart.Colors[1],
  77. pointBorderColor: sitesChart.Colors[1],
  78. pointBackgroundColor: "#fff",
  79. data: sitesChart.ChartT2
  80. },
  81. {
  82. label: "Team3",
  83. fill: false,
  84. borderColor: sitesChart.Colors[2],
  85. pointBorderColor: sitesChart.Colors[2],
  86. pointBackgroundColor: "#fff",
  87. data: sitesChart.ChartT3
  88. }
  89. ]
  90. }
  91.  
  92. // Line chart options.
  93. var options = {
  94. responsive: false,
  95. scaleOverride: true,
  96. scaleSteps: 10,
  97. scaleStepWidth: 10,
  98. scaleStartValue: 0,
  99. pointDotRadius: 7,
  100. datasetFill: false
  101. };
  102.  
  103.  
  104. var chart = $('#lineChart').get(0).getContext("2d");
  105.  
  106. new Chart(chart, {
  107. type: 'line',
  108. data: data,
  109. options: options
  110. });
  111.  
  112. return '';
  113. }
  114.  
  115. if(ctx.view === "{31BD318D-04D3-4B78-8F50-30855F8D5B75}"){
  116. var data = {
  117. labels: sitesChart.ChartTitle,
  118. datasets: [
  119. {
  120. label: "Team1",
  121. fill: false,
  122. borderColor: sitesChart.Colors[0],
  123. pointBorderColor: sitesChart.Colors[0],
  124. pointBackgroundColor: "#fff",
  125. data: sitesChart.ChartT1
  126. },
  127. {
  128. label: "Team2",
  129. fill: false,
  130. borderColor: sitesChart.Colors[1],
  131. pointBorderColor: sitesChart.Colors[1],
  132. pointBackgroundColor: "#fff",
  133. data: sitesChart.ChartT2
  134. },
  135. {
  136. label: "Team3",
  137. fill: false,
  138. borderColor: sitesChart.Colors[2],
  139. pointBorderColor: sitesChart.Colors[2],
  140. pointBackgroundColor: "#fff",
  141. data: sitesChart.ChartT3
  142. }
  143. ]
  144. }
  145.  
  146. // Line chart options.
  147. var options = {
  148. responsive: false,
  149. scaleOverride: true,
  150. scaleSteps: 10,
  151. scaleStepWidth: 10,
  152. scaleStartValue: 0,
  153. pointDotRadius: 7,
  154. datasetFill: false
  155. };
  156.  
  157.  
  158. var chart = $('#lineChart2').get(0).getContext("2d");
  159.  
  160. new Chart(chart, {
  161. type: 'bar',
  162. data: data,
  163. options: options
  164. });
  165.  
  166. return '';
  167. }
  168. return RenderFooterTemplate(ctx);
  169. }
  170.  
  171. $(document).ready(sitesChart.FieldRenderSetup());// JavaScript source code
Add Comment
Please, Sign In to add comment