chart.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. function displayfileData(allData) {
  2. allData.forEach( (usager) => {
  3. let identite = usager.identite;
  4. let situation = usager.situation;
  5. let frequentation = usager.frequentation;
  6. let espace = usager.espace;
  7. let telephone = usager.telephone;
  8. });
  9. }
  10. function freqBySpace(allData) {
  11. //console.log(allData);
  12. var accueilArr = [];
  13. var espace1Arr = [];
  14. var espace2Arr = [];
  15. var espace3Arr = [];
  16. var espace4Arr = [];
  17. var espace5Arr = [];
  18. var espace6Arr = [];
  19. allData.forEach( (usager) => {
  20. //console.log(book.format);
  21. switch (usager.espace) {
  22. case "Espace accueil":
  23. //console.log("in E!");
  24. accueilArr.push(usager.frequentation);
  25. break;
  26. case "realite virtuelle":
  27. //console.log("in H!");
  28. espace1Arr.push(usager.frequentation);
  29. break;
  30. case "musee numerique":
  31. //console.log("in P!");
  32. espace2Arr.push(usager.frequentation);
  33. break;
  34. case "cyber base":
  35. //console.log("in H!");
  36. espace3Arr.push(usager.frequentation);
  37. break;
  38. case "shooting photo":
  39. //console.log("in P!");
  40. espace4Arr.push(usager.frequentation);
  41. break;
  42. case "jeux videos":
  43. //console.log("in H!");
  44. espace5Arr.push(usager.frequentation);
  45. break;
  46. case "espace scenique":
  47. //console.log("in P!");
  48. espace6Arr.push(usager.frequentation);
  49. break;
  50. default:
  51. break;
  52. }
  53. });
  54. //console.log(ebookArr, hardcoverArr, paperbackArr);
  55. var sumAccueilFreq = getArrayAverage(accueilArr);
  56. var sumEspace1Freq = getArrayAverage(espace1Arr);
  57. var sumEspace2Freq = getArrayAverage(espace2Arr);
  58. var sumEspace3Freq = getArrayAverage(espace3Arr);
  59. var sumEspace4Freq = getArrayAverage(espace4Arr);
  60. var sumEspace5Freq = getArrayAverage(espace5Arr);
  61. var sumEspace6Freq = getArrayAverage(espace6Arr);
  62. console.log(sumAccueilFreq, sumEspace1Freq, sumEspace2Freq,sumEspace3Freq,sumEspace4Freq,sumEspace5Freq,sumEspace6Freq);
  63. return {
  64. "title": "Fréquentation des espaces de microfolies",
  65. "key": "Total fréquentation",
  66. "espaceFormat": ["Espace accueil", "realite virtuelle", "musee numerique", "cyber base", "shooting photo", "jeux videos", "espace scenique"],
  67. "avePrice": [sumAccueilFreq, sumEspace1Freq, sumEspace2Freq, sumEspace3Freq, sumEspace4Freq, sumEspace5Freq, sumEspace6Freq]
  68. };
  69. }
  70. function getArrayAverage(arr) {
  71. total = 0;
  72. arr.forEach( (frequentation) => {
  73. total += frequentation;
  74. });
  75. //var average = (total / arr.length).toFixed(2);
  76. return total;
  77. }
  78. function createChartToDOM(titleInfo, xLabelInfo, legendKeyLabel, dataInfo) {
  79. var data = {
  80. //labels: [],
  81. labels: xLabelInfo,
  82. datasets: [{
  83. label: legendKeyLabel,
  84. borderColor: "rgb(255, 99, 132)",
  85. backgroundColor: "rgba(255, 99, 132, 0.5)",
  86. borderWidth: 1,
  87. data: dataInfo,
  88. fill: false,
  89. }]
  90. }
  91. var options = {
  92. scales: {
  93. xAxes: [{
  94. //display: false,
  95. ticks: {}
  96. }],
  97. yAxes: [{
  98. display: true,
  99. scaleLabel: {
  100. display: true,
  101. labelString: 'FREQUENTATION ',
  102. fontSize: 18,
  103. fontColor: "#333",
  104. },
  105. ticks: {
  106. beginAtZero: true
  107. }
  108. }],
  109. xAxes: [{
  110. scaleLabel: {
  111. display: true,
  112. labelString: 'ESPACES',
  113. fontSize: 18,
  114. fontColor: "#333",
  115. }
  116. }]
  117. },
  118. elements: {
  119. line: {
  120. tension: 0.1, // disables bezier curves
  121. }
  122. },
  123. layout: {
  124. padding: {
  125. left: 10,
  126. right: 10,
  127. top: 0,
  128. bottom: 0
  129. }
  130. },
  131. /*
  132. title: {
  133. display: true,
  134. fontSize: 36,
  135. fontFamily: "monospace",
  136. fontColor: "#333",
  137. text: titleInfo,
  138. bottom: 30
  139. },
  140. */
  141. legend: {
  142. display: false,
  143. }
  144. }
  145. // CREATES AND DISPLAYS CHARTJS OBJECt
  146. var context = document.getElementById("myChart").getContext("2d");
  147. var myChart = new Chart(context, {
  148. type: "bar",
  149. data: data,
  150. options: options
  151. });
  152. }