Browse Source

[FIX] Cambiar gráfico de barra por gráfico de torta

Adrielso 7 years ago
parent
commit
b1a0347773

+ 36 - 12
static/src/js/widgets/ranking_sales_partner.js

@@ -114,45 +114,69 @@ function ranking_sales_partner (widget) {
             var body = [];
             var item;
             var rank = 10;
+            rank= ranking.length;
 
             for (var i = 0; i < rank; i++) {
                 if (ranking[i]){
                     item = ranking[i];
-                } else {
-                    item = {};
-                    item.name = "N/A";
-                    item.countInvoice = 0;
                 }
+
                 label.push(item.name);
                 body.push(item.countInvoice);
             }
+
             var chart = new Chart(this.$el.find(".widget-content").find('canvas'), {
-                // type: 'doughnut',
-                type: 'horizontalBar',
-                // type: '',
+                type: 'pie',
                 data: {
                     labels: label,
                     datasets: [
                         {
-                            backgroundColor: ['#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1'],
+                            backgroundColor: ['#01579B','#0277BD','#0288D1','#039BE5','#03A9F4','#29B6F6','#4FC3F7','#81D4FA','#B3E5FC','#E1F5FE'],
                             data: body,
                         }
                     ]
                 },
                 options: {
+                    animation: {
+                        animateScale: true,
+                        animateRotate: true
+                    },
                     maintainAspectRatio: false,
                     layout: {
                         padding: 20
                     },
-                    scales: {
-                        xAxes: [{ stacked: true }],
-                        yAxes: [{ stacked: true }],
-                    },
                     legend: {
                         display: false,
                     },
                 }
             });
+            // var chart = new Chart(this.$el.find(".widget-content").find('canvas'), {
+            //     // type: 'doughnut',
+            //     type: 'horizontalBar',
+            //     // type: '',
+            //     data: {
+            //         labels: label,
+            //         datasets: [
+            //             {
+            //                 backgroundColor: ['#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1'],
+            //                 data: body,
+            //             }
+            //         ]
+            //     },
+            //     options: {
+            //         maintainAspectRatio: false,
+            //         layout: {
+            //             padding: 20
+            //         },
+            //         scales: {
+            //             xAxes: [{ stacked: true }],
+            //             yAxes: [{ stacked: true }],
+            //         },
+            //         legend: {
+            //             display: false,
+            //         },
+            //     }
+            // });
         },
 
         showCustomers: function (e) {

+ 9 - 11
static/src/js/widgets/ranking_sales_product.js

@@ -112,6 +112,7 @@ function ranking_sales_product (widget) {
                             return meno + num
                         }, 0);
                         lineUnik = itemLine.shift();
+                        console.log(lineUnik);
                         ranking.push({
                             product: lineUnik.product_id[1],
                             qty: cat,
@@ -146,40 +147,37 @@ function ranking_sales_product (widget) {
             var body = [];
             var item;
             var rank = 10;
+            rank= ranking.length;
 
             for (var i = 0; i < rank; i++) {
                 if (ranking[i]){
                     item = ranking[i];
-                } else {
-                    item = {};
-                    item.product = "N/A";
-                    item.qty = 0;
                 }
+
                 label.push(item.product);
                 body.push(item.qty);
             }
             var chart = new Chart(this.$el.find(".widget-content").find('canvas'), {
                 // type: 'doughnut',
-                type: 'horizontalBar',
-                // type: '',
+                type: 'pie',
                 data: {
                     labels: label,
                     datasets: [
                         {
-                            backgroundColor: ['#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1', '#0288d1'],
+                            backgroundColor: ['#01579B','#0277BD','#0288D1','#039BE5','#03A9F4','#29B6F6','#4FC3F7','#81D4FA','#B3E5FC','#E1F5FE'],
                             data: body,
                         }
                     ]
                 },
                 options: {
+                    animation: {
+                        animateScale: true,
+                        animateRotate: true
+                    },
                     maintainAspectRatio: false,
                     layout: {
                         padding: 20
                     },
-                    scales: {
-                        xAxes: [{ stacked: true }],
-                        yAxes: [{ stacked: true }],
-                    },
                     legend: {
                         display: false,
                     },