chart.js 3.8 KB

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