Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 961bd689

Von Bernd Bleßmann vor mehr als 1 Jahr hinzugefügt

  • ID 961bd6899e73d135960a86617ee09501d156b540
  • Vorgänger 0cbda6c9
  • Nachfolger 3ed8f261

Kunden-/Lieferanten-Umsatzstatistik als Chart (chart.js)

Unterschiede anzeigen:

js/kivi.CustomerVendorTurnover.js
42 42
    $('#turnovers').load(url);
43 43
  };
44 44

  
45
  ns.show_turnover_chart = function(period) {
46
    const html = '<div class="chart-container" style="position: relative;">'
47
               + '<canvas id="chart"></canvas>'
48
               + '</div>';
49
    $('#turnovers').html(html);
50

  
51
    let mode = "month";
52
    if (period === 'y') {
53
      mode    = "year";
54
    } else if (period === 'm') {
55
      mode    = "month";
56
    }
57

  
58
    const data = { action: 'CustomerVendorTurnover/turnover.json',
59
                   id:   $('#cv_id').val(),
60
                   db:   $('#db').val(),
61
                   mode: mode
62
                 };
63
    $.getJSON('controller.pl', data, function( returned_data ) {
64
      ns.draw_chart(returned_data);
65
      $("html, body").animate({ scrollTop: $("#chart").offset().top }, "slow");
66
    });
67
  };
68

  
69
  ns.draw_chart = function(data) {
70
    // Todos are most probably better done in the perl backend.
71
    // Todo: fill holes
72
    // Todo: show amount/paid in one/each bar
73
    // data = [
74
    //   {date_part: 2022, netamount: 1234.4},
75
    //   {date_part: 2022, netamount: 234.4},
76
    //   {date_part: 2021, netamount: 234.4},
77
    //   {date_part: 2021, netamount: 34.4},
78
    //   {date_part: 2020, netamount: 134.4},
79
    //   {date_part: 2018, netamount: 34.4}
80
    // ];
81

  
82
    $(data).each(function(idx, elt) {
83
      elt.date_part = '' + elt.date_part;
84
    });
85

  
86
    ns.chart(data);
87
  };
88

  
89
  ns.chart = function(data) {
90
    const ctx = 'chart';
91
    const myChart = new Chart(ctx, {
92
      type: 'bar',
93
      data: {
94
        datasets: [{
95
          label: kivi.t8('Net.Turnover'),
96
          data: data,
97
          backgroundColor: [
98
            'rgba(255, 99, 132, 0.2)',
99
            'rgba(54, 162, 235, 0.2)',
100
            'rgba(255, 206, 86, 0.2)',
101
            'rgba(75, 192, 192, 0.2)',
102
            'rgba(153, 102, 255, 0.2)',
103
            'rgba(255, 159, 64, 0.2)'
104
          ],
105
          borderColor: [
106
            'rgba(255, 99, 132, 1)',
107
            'rgba(54, 162, 235, 1)',
108
            'rgba(255, 206, 86, 1)',
109
            'rgba(75, 192, 192, 1)',
110
            'rgba(153, 102, 255, 1)',
111
            'rgba(255, 159, 64, 1)'
112
          ],
113
          borderWidth: 1
114
        }]
115
      },
116
      options: {
117
        scales: {
118
          y: {
119
            beginAtZero: true
120
          }
121
        },
122
        parsing: {
123
          xAxisKey: 'date_part',
124
          yAxisKey: 'netamount'
125
        }
126
      }
127
    });
128
  };
129

  
130
  ns.sample_chart = function() {
131
    const ctx = 'chart';
132
    const myChart = new Chart(ctx, {
133
      type: 'bar',
134
      data: {
135
        labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
136
        datasets: [{
137
          label: '# of Votes',
138
          data: [12, 19, 3, 5, 2, 3],
139
          backgroundColor: [
140
            'rgba(255, 99, 132, 0.2)',
141
            'rgba(54, 162, 235, 0.2)',
142
            'rgba(255, 206, 86, 0.2)',
143
            'rgba(75, 192, 192, 0.2)',
144
            'rgba(153, 102, 255, 0.2)',
145
            'rgba(255, 159, 64, 0.2)'
146
          ],
147
          borderColor: [
148
            'rgba(255, 99, 132, 1)',
149
            'rgba(54, 162, 235, 1)',
150
            'rgba(255, 206, 86, 1)',
151
            'rgba(75, 192, 192, 1)',
152
            'rgba(153, 102, 255, 1)',
153
            'rgba(255, 159, 64, 1)'
154
          ],
155
          borderWidth: 1
156
        }]
157
      },
158
      options: {
159
        scales: {
160
          y: {
161
            beginAtZero: true
162
          }
163
        }
164
      }
165
    });
166
  };
167

  
45 168
  ns.cv_tabs_init = function () {
46 169
    $("#customer_vendor_tabs").on('tabsbeforeactivate', function(event, ui){
47 170
      if (ui.newPanel.attr('id') == 'quotations') {

Auch abrufbar als: Unified diff