Advertisement
Guest User

fetch week

a guest
Mar 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function fetchWeekInfo(week) {
  3.     fetch(`/transfer-system/dashboard/week/${week}`)
  4.         .then((res) => {
  5.             return res.json()
  6.         })
  7.         .then((res) => {
  8.  
  9.             let wrapper = document.querySelector("#wrapper-chart");
  10.            
  11.             wrapper.innerHTML = res.canvas;
  12.  
  13.             let titleWeek = document.querySelector("#title-week");
  14.  
  15.             let dataUpload = res.dataUpload;
  16.             let dataDownload = res.dataDownload;
  17.             let dataExtUpload = res.dataExtUpload;
  18.  
  19.             // console.log(dataExtUpload);
  20.             titleWeek.innerHTML = `Semaine n°${dataExtUpload[0].week}`;
  21.  
  22.             let arrayUpload = arrayShowUploadFiles(dataUpload);
  23.             let arrayDownload = arrayShowDownloadFiles(dataDownload);
  24.             let arrayExt = createLabelForExtUpload(dataExtUpload);
  25.             let arrayDataExt = createArrayForDataExtUpload(dataExtUpload);
  26.             // let arrayRandomColors = createArrayWithRandomColorForData(arrayDataExt);
  27.  
  28.             // Bar chart
  29.             let uploadCharts = new Chart(document.getElementById("chartUpload"), {
  30.                 type: 'bar',
  31.                 data: {
  32.                     labels: ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"],
  33.                     datasets: [{
  34.                         label: "Upload by date",
  35.                         backgroundColor: ["#3e95cd", "#8e5ea2", "#3cba9f", "#e8c3b9", "#c45850", "#3cba9f", "#3e95cd"],
  36.                         data: arrayUpload
  37.                     }]
  38.                 },
  39.                 options: {
  40.                     legend: {
  41.                         display: false
  42.                     },
  43.                     title: {
  44.                         display: true,
  45.                         text: 'UPLOAD/Jours'
  46.                     }
  47.                 }
  48.             });
  49.  
  50.             let downloadCharts = new Chart(document.getElementById("chartDownload"), {
  51.                 type: 'line',
  52.                 data: {
  53.                     labels: ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"],
  54.                     datasets: [{
  55.                         label: "Download by date",
  56.                         // backgroundColor: ["#3e95cd", "#8e5ea2", "#3cba9f", "#e8c3b9", "#c45850", "#3cba9f", "#3e95cd"],
  57.                         fill: true,
  58.                         borderColor: "#3cba9f",
  59.                         data: arrayDownload
  60.                     }]
  61.                 },
  62.                 options: {
  63.                     legend: {
  64.                         display: false
  65.                     },
  66.                     title: {
  67.                         display: true,
  68.                         text: 'DOWNLOAD/Jours'
  69.                     }
  70.                 }
  71.             });
  72.  
  73.             //
  74.             new Chart(document.getElementById("chartExtUpload"), {
  75.                 type: 'pie',
  76.                 data: {
  77.                   labels: arrayExt,
  78.                   datasets: [{
  79.                     label: "Extension des fichiers téléchargés",
  80.                     // backgroundColor: arrayRandomColors,
  81.                     backgroundColor: ["#C5E9FF", "#6F0CE8", "#FF0000", "#E8A13C", "#FFFD48", "#24E82D", "#FFC5F6", "#2D06FF", "#FF8A02"],
  82.                     data: arrayDataExt
  83.                   }]
  84.                 },
  85.                 options: {
  86.                   title: {
  87.                     display: true,
  88.                     text: 'Extension des fichiers téléchargés'
  89.                   }
  90.                 }
  91.             });
  92.  
  93.  
  94.         })
  95.         .catch((err) => {
  96.             if (err) throw err;
  97.         })
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement