]> wagnertech.de Git - mfinanz.git/blob - js/kivi.ChartReport.js
date error in mapping
[mfinanz.git] / js / kivi.ChartReport.js
1 namespace('kivi.ChartReport', function(ns) {
2   "use strict";
3
4   ns.data = undefined;
5
6   ns.background_colors = function() { return [
7     'rgba(255, 0, 0, 0.2)',
8     'rgba(63, 0, 0, 0.2)',
9     'rgba(0, 127, 0, 0.2)',
10     'rgba(0, 0, 191, 0.2)',
11     'rgba(191, 0, 0, 0.2)',
12     'rgba(0, 255, 0, 0.2)',
13     'rgba(0, 63, 0, 0.2)',
14     'rgba(0, 0, 127, 0.2)',
15     'rgba(127, 0, 0, 0.2)',
16     'rgba(0, 191, 0, 0.2)',
17     'rgba(0, 0, 255, 0.2)',
18     'rgba(0, 0, 63, 0.2)'
19   ]};
20
21   ns.border_colors = function() { return [
22     'rgba(255, 0, 0, 1.0)',
23     'rgba(63, 0, 0, 1.0)',
24     'rgba(0, 127, 0, 1.0)',
25     'rgba(0, 0, 191, 1.0)',
26     'rgba(191, 0, 0, 1.0)',
27     'rgba(0, 255, 0, 1.0)',
28     'rgba(0, 63, 0, 1.0)',
29     'rgba(0, 0, 127, 1.0)',
30     'rgba(127, 0, 0, 1.0)',
31     'rgba(0, 191, 0, 1.0)',
32     'rgba(0, 0, 255, 1.0)',
33     'rgba(0, 0, 63, 1.0)'
34   ]};
35
36   ns.chart = function() {
37     $(ns.data.datasets).each(function(idx, elt) {
38       $(elt).each(function(idx) {elt[idx] = kivi.parse_amount('' + elt[idx]);console.log(elt[idx]);});
39     });
40
41     const datasets = [];
42     for (let i = 0; i < ns.data.data_labels.length; i++) {
43       const set = [];
44       $(ns.data.datasets).each(function(idx, elt) {set.push(elt[i]);});
45       const colots = [];
46       datasets.push({label: ns.data.data_labels[i],
47                      data: set,
48                      backgroundColor: ns.background_colors()[i % ns.background_colors().length],
49                      borderColor: ns.border_colors()[i % ns.border_colors().length],
50                      borderWidth: 1
51                     });
52     }
53
54     const ctx = 'chart';
55     const chart = new Chart(ctx, {
56       type: 'bar',
57       data: {
58         labels: ns.data.labels,
59         datasets: datasets,
60       },
61       options: {
62         scales: {
63           y: {
64             beginAtZero: true
65           }
66         }
67       }
68     });
69   };
70
71   ns.debug = function() {
72     console.log("bb: labels: "); console.log(ns.data.labels);
73     console.log("bb: datasets: "); console.log(ns.data.datasets);
74     console.log("bb: data_labels: "); console.log(ns.data.data_labels);
75   };
76
77   $(function() {
78     kivi.ChartReport.debug();
79     kivi.ChartReport.chart();
80   });
81 });