Переглянути джерело

Merge branch 'improvements' of onunez/soma-frontend into development

Oscar José Nuñez Chávez 5 роки тому
батько
коміт
7c25e9806a

+ 20 - 27
package-lock.json

@@ -611,12 +611,14 @@
             "minimist": {
               "version": "0.0.8",
               "bundled": true,
-              "dev": true
+              "dev": true,
+              "optional": true
             },
             "minipass": {
               "version": "2.3.5",
               "bundled": true,
               "dev": true,
+              "optional": true,
               "requires": {
                 "safe-buffer": "^5.1.2",
                 "yallist": "^3.0.0"
@@ -635,6 +637,7 @@
               "version": "0.5.1",
               "bundled": true,
               "dev": true,
+              "optional": true,
               "requires": {
                 "minimist": "0.0.8"
               }
@@ -2750,28 +2753,21 @@
       "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA=="
     },
     "chart.js": {
-      "version": "2.8.0",
-      "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-2.8.0.tgz",
-      "integrity": "sha512-Di3wUL4BFvqI5FB5K26aQ+hvWh8wnP9A3DWGvXHVkO13D3DSnaSsdZx29cXlEsYKVkn1E2az+ZYFS4t0zi8x0w==",
+      "version": "2.9.3",
+      "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-2.9.3.tgz",
+      "integrity": "sha512-+2jlOobSk52c1VU6fzkh3UwqHMdSlgH1xFv9FKMqHiNCpXsGPQa/+81AFa+i3jZ253Mq9aAycPwDjnn1XbRNNw==",
       "requires": {
         "chartjs-color": "^2.1.0",
         "moment": "^2.10.2"
       }
     },
     "chartjs-color": {
-      "version": "2.3.0",
-      "resolved": "https://registry.npmjs.org/chartjs-color/-/chartjs-color-2.3.0.tgz",
-      "integrity": "sha512-hEvVheqczsoHD+fZ+tfPUE+1+RbV6b+eksp2LwAhwRTVXEjCSEavvk+Hg3H6SZfGlPh/UfmWKGIvZbtobOEm3g==",
+      "version": "2.4.1",
+      "resolved": "https://registry.npmjs.org/chartjs-color/-/chartjs-color-2.4.1.tgz",
+      "integrity": "sha512-haqOg1+Yebys/Ts/9bLo/BqUcONQOdr/hoEr2LLTRl6C5LXctUdHxsCYfvQVg5JIxITrfCNUDr4ntqmQk9+/0w==",
       "requires": {
         "chartjs-color-string": "^0.6.0",
-        "color-convert": "^0.5.3"
-      },
-      "dependencies": {
-        "color-convert": {
-          "version": "0.5.3",
-          "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-0.5.3.tgz",
-          "integrity": "sha1-vbbGnOZg+t/+CwAHzER+G59ygr0="
-        }
+        "color-convert": "^1.9.3"
       }
     },
     "chartjs-color-string": {
@@ -4942,6 +4938,11 @@
         "pinkie-promise": "^2.0.0"
       }
     },
+    "hidpi-canvas": {
+      "version": "1.0.10",
+      "resolved": "https://registry.npmjs.org/hidpi-canvas/-/hidpi-canvas-1.0.10.tgz",
+      "integrity": "sha1-0OmZlr9LkaTeETfod8rPF0cWYU0="
+    },
     "hmac-drbg": {
       "version": "1.0.1",
       "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz",
@@ -6273,8 +6274,7 @@
             "minimist": {
               "version": "0.0.8",
               "bundled": true,
-              "dev": true,
-              "optional": true
+              "dev": true
             },
             "minipass": {
               "version": "2.3.5",
@@ -7815,7 +7815,6 @@
             "mkdirp": {
               "version": "0.5.1",
               "bundled": true,
-              "optional": true,
               "requires": {
                 "minimist": "0.0.8"
               }
@@ -7975,8 +7974,7 @@
             },
             "safe-buffer": {
               "version": "5.1.2",
-              "bundled": true,
-              "optional": true
+              "bundled": true
             },
             "safer-buffer": {
               "version": "2.1.2",
@@ -8068,8 +8066,7 @@
             },
             "yallist": {
               "version": "3.0.3",
-              "bundled": true,
-              "optional": true
+              "bundled": true
             }
           }
         },
@@ -9129,11 +9126,6 @@
       "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=",
       "dev": true
     },
-    "perfect-scrollbar": {
-      "version": "1.4.0",
-      "resolved": "https://registry.npmjs.org/perfect-scrollbar/-/perfect-scrollbar-1.4.0.tgz",
-      "integrity": "sha512-/2Sk/khljhdrsamjJYS5NjrH+GKEHEwh7zFSiYyxROyYKagkE4kSn2zDQDRTOMo8mpT2jikxx6yI1dG7lNP/hw=="
-    },
     "performance-now": {
       "version": "2.1.0",
       "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
@@ -12169,6 +12161,7 @@
               "version": "0.5.1",
               "bundled": true,
               "dev": true,
+              "optional": true,
               "requires": {
                 "minimist": "0.0.8"
               }

+ 2 - 1
package.json

@@ -36,13 +36,14 @@
     "bootstrap-material-design": "^4.1.2",
     "bootstrap-select": "^1.13.12",
     "c": "^0.1.0",
-    "chart.js": "^2.8.0",
+    "chart.js": "^2.9.3",
     "classlist.js": "^1.1.20150312",
     "crypto-js": "^3.1.9-1",
     "datatables.net": "^1.10.19",
     "datatables.net-dt": "^1.10.19",
     "font-awesome": "^4.7.0",
     "hammerjs": "^2.0.8",
+    "hidpi-canvas": "^1.0.10",
     "jquery": "^3.4.1",
     "leaflet": "^1.5.1",
     "leaflet-routing-machine": "^3.2.12",

+ 17 - 8
src/app/components/assets/assets.component.html

@@ -76,7 +76,7 @@
         <div class="row p-0">
           <div class="col-xl-6 col-md-6 col-sm-12 p-1">
             <div class="widget energy-stats">
-              <div class="mini-stats ">
+              <div class="mini-stats">
                 <span class="sky-skin"><i class="fa fa-bolt"></i></span>
                 <h3 *ngIf="eProduced">
                   {{ energyDay }}
@@ -89,7 +89,7 @@
 
           <div class="col-xl-6 col-md-6 col-sm-12 p-1">
             <div class="widget energy-stats">
-              <div class="mini-stats ">
+              <div class="mini-stats">
                 <span class="dark-yellow-skin"><i class="fa fa-bolt"></i></span>
                 <h3 *ngIf="eProduced">
                   {{ energyWeek }}
@@ -102,7 +102,7 @@
 
           <div class="col-xl-6 col-md-6 col-sm-12 p-1">
             <div class="widget energy-stats">
-              <div class="mini-stats ">
+              <div class="mini-stats">
                 <span class="yellow-skin"><i class="fa fa-bolt"></i></span>
                 <h3 *ngIf="eProduced">
                   {{ energyMonth }}
@@ -115,7 +115,7 @@
 
           <div class="col-xl-6 col-md-6 col-sm-12 p-1">
             <div class="widget energy-stats">
-              <div class="mini-stats ">
+              <div class="mini-stats">
                 <span class="green-skin"><i class="fa fa-bolt"></i></span>
                 <h3 *ngIf="eProduced">
                   {{ energyYear }}
@@ -154,7 +154,7 @@
                 </span>
               </div>
               <div class="cdo-items">
-                <i class="material-icons ">
+                <i class="material-icons">
                   money
                 </i>
                 Monto total por CdO generados:
@@ -178,7 +178,7 @@
                 </p>
 
                 <div class="visualization">
-                  <div class=" action-buttons">
+                  <div class="action-buttons">
                     <button
                       class="btn btn-link"
                       [class.btn-success]="isActive[0]"
@@ -262,7 +262,7 @@
                       </div>
                     </div>
                   </div>
-                  <div class=" action-buttons">
+                  <div class="action-buttons">
                     <button
                       title="Barra"
                       [ngClass]="[
@@ -306,7 +306,16 @@
             </div>
 
             <div class="chart-container" id="chart-wrapper">
-              <canvas id="canvas">{{ chart1 }}</canvas>
+              <canvas
+                baseChart
+                *ngIf="barChartData"
+                id="canvas"
+                [datasets]="barChartData"
+                [labels]="barChartLabels"
+                [options]="barChartOptions"
+                [plugins]="barChartPlugins"
+                [chartType]="barChartType"
+              ></canvas>
             </div>
             <div class="no-data">
               <h2>

+ 243 - 93
src/app/components/assets/assets.component.ts

@@ -22,7 +22,7 @@ import * as $ from "jquery";
 @Component({
   selector: "app-assets",
   templateUrl: "./assets.component.html",
-  styleUrls: ["./assets.component.scss"]
+  styleUrls: ["./assets.component.scss"],
 })
 export class AssetsComponent implements OnInit {
   exportExcel = ExportType.XLSX;
@@ -31,7 +31,7 @@ export class AssetsComponent implements OnInit {
   ExcelOptions: ExcelOptions = {
     fileName: "data-Medidores",
     sheet: "Hoja 1",
-    Props: { Author: "INVERLEC" }
+    Props: { Author: "INVERLEC" },
   };
   CSVOptions: Options = { fileName: "data-Medidores" };
   JSONOptions: Options = { fileName: "data-Medidores" };
@@ -83,7 +83,7 @@ export class AssetsComponent implements OnInit {
     we: "Mie",
     th: "Jue",
     fr: "Vie",
-    sa: "Sab"
+    sa: "Sab",
   };
   monthsLabels: any = {
     1: "Ene",
@@ -97,13 +97,13 @@ export class AssetsComponent implements OnInit {
     9: "Sep",
     10: "Oct",
     11: "Nov",
-    12: "Dic"
+    12: "Dic",
   };
   myDpOptions: IAngularMyDpOptions = {
     dateRange: false,
     dateFormat: "dd/mm/yyyy",
     dayLabels: this.daysLabels,
-    monthLabels: this.monthsLabels
+    monthLabels: this.monthsLabels,
   };
   myDateInit: boolean = true;
   model: IMyDateModel = null;
@@ -126,7 +126,7 @@ export class AssetsComponent implements OnInit {
   // For chartjs
   chartjs: boolean;
   chart1: Chart;
-  chart1Type: string;
+  chart1Type;
   barChartColors: any = [
     "#5f86b0",
     "#a9d0ea",
@@ -135,7 +135,7 @@ export class AssetsComponent implements OnInit {
     "#f2e8cf",
     "#3c8dbc",
     "#f56954",
-    "#ee964b"
+    "#ee964b",
   ];
   borderChartColors: any = [
     "#4573a5",
@@ -145,7 +145,7 @@ export class AssetsComponent implements OnInit {
     "#d3cbb7",
     "#539dc8",
     "#e4604c",
-    "#d38d51"
+    "#d38d51",
   ];
   public barChartType: ChartType;
   public barChartLegend: boolean;
@@ -153,6 +153,7 @@ export class AssetsComponent implements OnInit {
   public barChartOptions: ChartOptions;
   public barChartData: ChartDataSets[];
   @ViewChild("baseChart", null) chart: BaseChartDirective;
+
   city: any;
   total_savings: any;
   last_day_savings: number;
@@ -172,14 +173,14 @@ export class AssetsComponent implements OnInit {
     // DEMO
     this.userLevel = +this.authService.getUserLevel();
     // Get selected asset
-    this.route.queryParams.subscribe(params => {
+    this.route.queryParams.subscribe((params) => {
       this.assetID = params["id"];
     });
 
     Swal.fire({
       allowOutsideClick: false,
       type: "info",
-      text: "Espere por favor..."
+      text: "Espere por favor...",
     });
     Swal.showLoading();
   }
@@ -195,9 +196,9 @@ export class AssetsComponent implements OnInit {
           date: {
             year: begin.getFullYear(),
             month: begin.getMonth() + 1,
-            day: begin.getDate()
-          }
-        }
+            day: begin.getDate(),
+          },
+        },
       };
     }
 
@@ -211,14 +212,14 @@ export class AssetsComponent implements OnInit {
       false,
       false,
       false,
-      false
+      false,
     ];
 
     this.chartActive = [true, false, false, false];
 
     // Get all assets (according to user's assigned organizations)
     let plants = this.plantsService.getAllAssets().subscribe(
-      res => {
+      (res) => {
         this.listAssets = res["data"]["assets"];
 
         // Default values for chart
@@ -230,12 +231,12 @@ export class AssetsComponent implements OnInit {
           this.city = this.listAssets[0].city;
         } else {
           this.city = this.listAssets.find(
-            object => object.id == this.assetID
+            (object) => object.id == this.assetID
           ).city;
         }
 
         let tempAsset = this.listAssets.find(
-          object => object.id == this.assetID
+          (object) => object.id == this.assetID
         );
 
         if (tempAsset["meters_installed"].length > 0) {
@@ -254,11 +255,11 @@ export class AssetsComponent implements OnInit {
           this.metersInstalled = false;
         }
       },
-      err => {
+      (err) => {
         Swal.fire({
           type: "error",
           title: "Error en el servidor",
-          text: err.message
+          text: err.message,
         });
       }
     );
@@ -287,7 +288,7 @@ export class AssetsComponent implements OnInit {
   // Trigger again the chart with the selected assetID
   onChangeObj(event: any) {
     this.assetID = event.target.value;
-    let tempAsset = this.listAssets.find(object => object.id == this.assetID);
+    let tempAsset = this.listAssets.find((object) => object.id == this.assetID);
     this.city = tempAsset["city"];
     this.total_savings = 0;
     this.last_day_savings = 0;
@@ -301,7 +302,7 @@ export class AssetsComponent implements OnInit {
       Swal.fire({
         allowOutsideClick: false,
         type: "info",
-        text: "Espere por favor..."
+        text: "Espere por favor...",
       });
       Swal.showLoading();
       setTimeout(() => {
@@ -311,7 +312,8 @@ export class AssetsComponent implements OnInit {
           this.chart1.destroy();
         }
         this.chart1 = undefined;
-        this.chart1 = new Chart("canvas", {});
+        const ctx = new CanvasRenderingContext2D();
+        this.chart1 = new Chart(ctx, {});
       }, 3000);
     }
   }
@@ -325,7 +327,7 @@ export class AssetsComponent implements OnInit {
   }
 
   getSavings(assetID: string) {
-    this.plantsService.getAssetSavings(this.assetID).subscribe(res => {
+    this.plantsService.getAssetSavings(this.assetID).subscribe((res) => {
       this.total_savings = res["data"]["ahorro_total"];
       this.total_savings =
         +this.total_savings > 10000
@@ -337,7 +339,7 @@ export class AssetsComponent implements OnInit {
   }
 
   getEnvironmentalData(assetID: string) {
-    this.logsService.getAssetEnviromentalStats(assetID).subscribe(resp => {
+    this.logsService.getAssetEnviromentalStats(assetID).subscribe((resp) => {
       this.environment = resp["data"]["environmentals"];
       this.environmentCO2 = this.environment.avoided_kg_of_co2.toFixed(2);
       this.environmentHouse = this.environment.number_of_homes.toFixed(0);
@@ -352,7 +354,7 @@ export class AssetsComponent implements OnInit {
     let energy_produced = this.logsService
       .getEnergySummaryByAsset(assetID)
       .subscribe(
-        resp => {
+        (resp) => {
           this.eProduced = resp["data"]["energy"]; //results[1];
           this.energyDay = this.eProduced.today.total_energy_kWh || 0;
           this.energyWeek =
@@ -368,11 +370,11 @@ export class AssetsComponent implements OnInit {
               ? (this.eProduced.lifeTime.total_energy_kWh / 1000).toFixed(2)
               : this.eProduced.lifeTime.total_energy_kWh || 0;
         },
-        err => {
+        (err) => {
           Swal.fire({
             type: "error",
             title: "Error en el servidor",
-            text: "No su pudo obtener la informacion"
+            text: "No su pudo obtener la informacion",
           });
         }
       );
@@ -389,7 +391,7 @@ export class AssetsComponent implements OnInit {
       Swal.fire({
         allowOutsideClick: false,
         type: "info",
-        text: "Espere por favor..."
+        text: "Espere por favor...",
       });
       Swal.showLoading();
     }
@@ -431,7 +433,7 @@ export class AssetsComponent implements OnInit {
           false,
           false,
           false,
-          false
+          false,
         ];
         break;
       case "week":
@@ -445,7 +447,7 @@ export class AssetsComponent implements OnInit {
           false,
           false,
           false,
-          false
+          false,
         ];
         break;
       case "WTD":
@@ -459,7 +461,7 @@ export class AssetsComponent implements OnInit {
           false,
           false,
           false,
-          false
+          false,
         ];
         break;
       case "month":
@@ -473,7 +475,7 @@ export class AssetsComponent implements OnInit {
           false,
           false,
           false,
-          false
+          false,
         ];
         break;
       case "MTD":
@@ -487,7 +489,7 @@ export class AssetsComponent implements OnInit {
           false,
           false,
           false,
-          false
+          false,
         ];
         break;
       case "3m":
@@ -501,7 +503,7 @@ export class AssetsComponent implements OnInit {
           true,
           false,
           false,
-          false
+          false,
         ];
         break;
       case "12m":
@@ -515,7 +517,7 @@ export class AssetsComponent implements OnInit {
           false,
           true,
           false,
-          false
+          false,
         ];
         break;
       case "YTD":
@@ -529,7 +531,7 @@ export class AssetsComponent implements OnInit {
           false,
           false,
           true,
-          false
+          false,
         ];
         break;
       case "total":
@@ -543,7 +545,7 @@ export class AssetsComponent implements OnInit {
           false,
           false,
           false,
-          true
+          true,
         ];
         break;
       default:
@@ -600,7 +602,7 @@ export class AssetsComponent implements OnInit {
               borderColor: "#ce2525",
               borderWidth: 2,
               yAxisID: "y-axis-ahorro",
-              fill: false
+              fill: false,
             });
             // The chart data object requires certain ordered params, so we itirate the returned object from the API call,
             // and build the new object with the required/needed values
@@ -615,18 +617,19 @@ export class AssetsComponent implements OnInit {
 
               let measure_values = Object.values(
                 this.metersValues[prop]["data"]
-                  .map(obj => obj.total_energy_kWh)
+                  .map((obj) => obj.total_energy_kWh)
                   .reverse()
               );
               this.metersData.push({
                 label: label,
                 backgroundColor: this.barChartColors[prop],
                 data: measure_values,
-                borderColor: this.borderChartColors[prop]
+                barPercentage: 0.7,
+                borderColor: this.borderChartColors[prop],
               });
               this.tableData.push({
                 headers: label,
-                dataValues: measure_values
+                dataValues: measure_values,
               });
             }
 
@@ -641,7 +644,7 @@ export class AssetsComponent implements OnInit {
               //let label = localStorage.getItem("email") == "inverlec@grupomerelec.com" ? `INVERLEC ${prop}` : this.metersValues[prop]["label"];
               let quantity = Object.keys(this.metersValues[0]["data"]);
               let mvalues = Object.values(
-                this.metersValues[prop]["data"].map(obj => obj).reverse()
+                this.metersValues[prop]["data"].map((obj) => obj).reverse()
               );
 
               for (let prop2 in quantity) {
@@ -682,38 +685,40 @@ export class AssetsComponent implements OnInit {
             switch (view) {
               case "day":
                 this.barChartLabels = this.metersValues[0]["data"]
-                  .map(obj =>
+                  .map((obj) =>
                     formatDate(obj.dateMin, "HH:mm ", "es-Es", "-0600")
                   )
                   .reverse();
                 break;
               case "week":
                 this.barChartLabels = this.metersValues[0]["data"]
-                  .map(obj =>
+                  .map((obj) =>
                     formatDate(obj.dateMax, "EEEE dd", "es-Es", "-0600")
                   )
                   .reverse();
                 break;
               case "year":
                 this.barChartLabels = this.metersValues[0]["data"]
-                  .map(obj =>
+                  .map((obj) =>
                     formatDate(obj.dateMax, "MM/yyyy", "es-Es", "-0600")
                   )
                   .reverse();
                 break;
               default:
                 this.barChartLabels = this.metersValues[0]["data"]
-                  .map(obj =>
+                  .map((obj) =>
                     formatDate(obj.dateMax, "dd/MM", "es-Es", "-0600")
                   )
                   .reverse();
             }
 
             // Push the values to the chart object
-            this.tableData.push({ headers: "Ahorro[US$]" });
+            this.tableData.push({
+              headers: "Ahorro[US$]",
+            });
             this.tableData.push({
               headers: "Fecha/Hora",
-              dataValues: this.barChartLabels
+              dataValues: this.barChartLabels,
             });
             this.tableData.reverse();
             for (let v in Object.keys(this.tableData)) {
@@ -735,17 +740,91 @@ export class AssetsComponent implements OnInit {
             this.dataSourcePrint.data = this.tableData2;
 
             this.showTable = true;
-            this.chart1 = new Chart("canvas", {
+
+            this.barChartType = this.chart1Type;
+            this.barChartLabels;
+            this.barChartOptions = {
+              title: {
+                display: true,
+              },
+              tooltips: {
+                mode: "index",
+                callbacks: {
+                  // Get the total of the energy produced in every point and show it in the hover tooltip
+                  label: function (tooltipItem, data) {
+                    var label =
+                      data.datasets[tooltipItem.datasetIndex].label || "";
+                    var value =
+                      data.datasets[tooltipItem.datasetIndex].data[
+                        tooltipItem.index
+                      ];
+                    var total = 0;
+
+                    for (var i = 1; i < data.datasets.length; i++)
+                      total += +data.datasets[i].data[tooltipItem.index];
+
+                    if (tooltipItem.datasetIndex !== data.datasets.length - 1) {
+                      return label + " : " + value;
+                    } else {
+                      return [
+                        label + " : " + value,
+                        "TOTAL[kWh] : " + Math.round(total),
+                      ];
+                    }
+                  },
+                },
+              },
+              responsive: true,
+              maintainAspectRatio: false,
+              scales: {
+                xAxes: [
+                  {
+                    stacked: true,
+                  },
+                ],
+                yAxes: [
+                  {
+                    stacked: true,
+                    position: "left",
+                    scaleLabel: {
+                      display: true,
+                      labelString: "Kilowatts hora [kWh]",
+                    },
+                  },
+                  {
+                    display: true,
+                    stacked: true,
+                    position: "right",
+                    id: "y-axis-ahorro",
+                    scaleLabel: {
+                      display: true,
+                      labelString: "Ahorro [US$]",
+                    },
+                    gridLines: {
+                      drawOnChartArea: false,
+                    },
+                  },
+                ],
+              },
+            };
+
+            this.barChartLegend = true;
+            this.barChartData = this.metersData;
+
+            /*
+            const ctx = new CanvasRenderingContext2D();
+
+            this.chart1 = new Chart(ctx, {
               type: this.chart1Type,
               options: {
                 title: {
-                  display: true
+                  display: true,
                 },
                 tooltips: {
                   mode: "index",
                   callbacks: {
                     // Get the total of the energy produced in every point and show it in the hover tooltip
-                    label: function(tooltipItem, data) {
+                    label: function (tooltipItem, data) {
                       var label =
                         data.datasets[tooltipItem.datasetIndex].label || "";
                       var value =
@@ -765,11 +844,11 @@ export class AssetsComponent implements OnInit {
                       } else {
                         return [
                           label + " : " + value,
-                          "TOTAL[kWh] : " + Math.round(total)
+                          "TOTAL[kWh] : " + Math.round(total),
                         ];
                       }
-                    }
-                  }
+                    },
+                  },
                 },
                 responsive: true,
                 maintainAspectRatio: false,
@@ -777,8 +856,8 @@ export class AssetsComponent implements OnInit {
                   xAxes: [
                     {
                       stacked: true,
-                      barPercentage: 0.7
-                    }
+                      barPercentage: 0.7,
+                    },
                   ],
                   yAxes: [
                     {
@@ -786,8 +865,8 @@ export class AssetsComponent implements OnInit {
                       position: "left",
                       scaleLabel: {
                         display: true,
-                        labelString: "Kilowatts hora [kWh]"
-                      }
+                        labelString: "Kilowatts hora [kWh]",
+                      },
                     },
                     {
                       display: true,
@@ -796,21 +875,21 @@ export class AssetsComponent implements OnInit {
                       id: "y-axis-ahorro",
                       scaleLabel: {
                         display: true,
-                        labelString: "Ahorro [US$]"
+                        labelString: "Ahorro [US$]",
                       },
                       gridLines: {
-                        drawOnChartArea: false
-                      }
-                    }
-                  ]
-                }
+                        drawOnChartArea: false,
+                      },
+                    },
+                  ],
+                },
               },
 
               data: {
                 labels: this.barChartLabels,
-                datasets: this.metersData
-              }
-            });
+                datasets: this.metersData,
+              },
+            }); */
             this.chartjs = true;
           });
       });
@@ -854,7 +933,7 @@ export class AssetsComponent implements OnInit {
       //properties: this.displayedColumns.join(","),
       header: '<h3 class="report-header">Datos de la planta </h3>',
       documentTitle: "DENMARK - Informacion generada",
-      style: ".report-header{ color: #075D9D; font-size: 24px; }"
+      style: ".report-header{ color: #075D9D; font-size: 24px; }",
     });
   }
 
@@ -869,42 +948,113 @@ export class AssetsComponent implements OnInit {
     switch (chartType) {
       case "bar":
         this.chartActive = [true, false, false, false];
-        if (this.metersData.find(v => v.type == "radar")) {
-          this.metersData.find(v => v.type != "line").type = "line";
+        if (this.metersData.find((v) => v.type == "radar")) {
+          this.metersData.find((v) => v.type != "line").type = "line";
         }
 
         break;
       case "line":
         this.chartActive = [false, true, false, false];
-        if (this.metersData.find(v => v.type == "radar")) {
-          this.metersData.find(v => v.type != "line").type = "line";
+        if (this.metersData.find((v) => v.type == "radar")) {
+          this.metersData.find((v) => v.type != "line").type = "line";
         }
         break;
       case "radar":
         this.chartActive = [false, false, true, false];
-        this.metersData.find(v => v.type == "line").type = "radar";
+        this.metersData.find((v) => v.type == "line").type = "radar";
         break;
       default:
     }
 
     this.chart1Type = chartType;
-
+    /*
     if (this.chart1 != undefined || this.chart1 == undefined) {
       this.chart1.destroy();
     }
-    this.chart1 = undefined;
-    this.chart1 = new Chart("canvas", {
+    this.chart1 = undefined;*/
+
+    this.barChartType = this.chart1Type;
+    this.barChartLabels;
+    this.barChartOptions = {
+      title: {
+        display: true,
+      },
+      tooltips: {
+        mode: "index",
+        callbacks: {
+          // Get the total of the energy produced in every point and show it in the hover tooltip
+          label: function (tooltipItem, data) {
+            var label = data.datasets[tooltipItem.datasetIndex].label || "";
+            var value =
+              data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
+            var total = 0;
+
+            for (var i = 1; i < data.datasets.length; i++)
+              total += +data.datasets[i].data[tooltipItem.index];
+
+            if (tooltipItem.datasetIndex !== data.datasets.length - 1) {
+              return label + " : " + value;
+            } else {
+              return [
+                label + " : " + value,
+                "TOTAL[kWh] : " + Math.round(total),
+              ];
+            }
+          },
+        },
+      },
+      responsive: true,
+      maintainAspectRatio: false,
+      scales: {
+        xAxes: [
+          {
+            stacked: true,
+          },
+        ],
+        yAxes: [
+          {
+            stacked: true,
+            position: "left",
+            scaleLabel: {
+              display: true,
+              labelString: "Kilowatts hora [kWh]",
+            },
+          },
+          {
+            display: true,
+            stacked: true,
+            position: "right",
+            id: "y-axis-ahorro",
+            scaleLabel: {
+              display: true,
+              labelString: "Ahorro [US$]",
+            },
+            gridLines: {
+              drawOnChartArea: false,
+            },
+          },
+        ],
+      },
+    };
+
+    this.barChartLegend = true;
+    this.barChartData = this.metersData;
+
+    /*
+    var canvas = document.getElementById("canvas");
+    const ctx = new CanvasRenderingContext2D();
+    this.chart1 = new Chart(ctx, {
       type: this.chart1Type,
 
       options: {
         title: {
-          display: true
+          display: true,
         },
         tooltips: {
           mode: "index",
           callbacks: {
             // Get the total of the energy produced in every point and show it in the hover tooltip
-            label: function(tooltipItem, data) {
+            label: function (tooltipItem, data) {
               var label = data.datasets[tooltipItem.datasetIndex].label || "";
               var value =
                 data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
@@ -918,8 +1068,8 @@ export class AssetsComponent implements OnInit {
               } else {
                 return [label + " : " + value, "TOTAL : " + Math.round(total)];
               }
-            }
-          }
+            },
+          },
         },
         responsive: true,
         maintainAspectRatio: false,
@@ -927,8 +1077,8 @@ export class AssetsComponent implements OnInit {
           xAxes: [
             {
               stacked: true,
-              barPercentage: 0.7
-            }
+              barPercentage: 0.7,
+            },
           ],
           yAxes: [
             {
@@ -936,8 +1086,8 @@ export class AssetsComponent implements OnInit {
               position: "left",
               scaleLabel: {
                 display: true,
-                labelString: "Kilowatts hora [kWh]"
-              }
+                labelString: "Kilowatts hora [kWh]",
+              },
             },
             {
               display: true,
@@ -946,19 +1096,19 @@ export class AssetsComponent implements OnInit {
               id: "y-axis-ahorro",
               scaleLabel: {
                 display: true,
-                labelString: "Ahorro [US$]"
+                labelString: "Ahorro [US$]",
               },
               gridLines: {
-                drawOnChartArea: false
-              }
-            }
-          ]
-        }
+                drawOnChartArea: false,
+              },
+            },
+          ],
+        },
       },
       data: {
         labels: this.barChartLabels,
-        datasets: this.metersData
-      }
-    });
+        datasets: this.metersData,
+      },
+    });*/
   }
 }