81
81
date ("Y-m-d " , strtotime ($ maxdag )) . "%' ORDER BY Datum_Dag, Naam ASC " ;
82
82
$ resultmd = mysqli_query ($ con , $ sqlmdinv ) or die ("Query failed. dag-max-dag " . mysqli_error ($ con ));
83
83
84
- if (mysqli_num_rows ($ resultmd ) != 0 ) {
84
+ if (mysqli_num_rows ($ resultmd ) > 0 ) {
85
85
while ($ row = mysqli_fetch_array ($ resultmd )) {
86
86
$ inverter_name = $ row ['Naam ' ];
87
87
$ time_only = substr ($ row ['Datum_Dag ' ], -9 );
88
88
$ today_max = $ chartdatestring . $ time_only ; // current chart date string + max time
89
89
$ today_max_utc = convertLocalDateTime ($ today_max ); // date in UTC
90
90
$ today_max_unix_utc = convertToUnixTimestamp ($ today_max_utc ); // unix timestamp in UTC
91
+ $ today_max_unix_utc = $ today_max_unix_utc - ($ today_max_unix_utc % 60 ); // round to nearest minute (skip seconds)
91
92
$ allValuesMaxDay [$ inverter_name ][$ today_max_unix_utc ] = intval ($ row ['gem ' ]);
92
93
// remember first and last date
93
94
if ($ max_first_val > $ today_max_unix_utc ) {
123
124
$ inverterValues = $ allValuesPerInverter [$ inverter_name ];
124
125
125
126
// loop over all times from all inverters from min to max
126
- for ($ time = $ max_first_val ; $ time <= $ max_last_val ; $ time += 300 ) {
127
+ for ($ time = $ max_first_val ; $ time <= $ max_last_val ; $ time += 300 ) {
127
128
$ currentInverterVal = "NaN " ;
128
129
$ timeInMillis = $ time * 1000 ;
129
130
if (isset ($ inverterValues [$ time ])) {
130
131
$ currentInverterVal = $ inverterValues [$ time ];
131
132
$ cumSum += ($ currentInverterVal / 12 );
132
- $ cumDataString .= "{x: $ timeInMillis, y: $ cumSum}, " ;
133
133
}
134
+ $ cumDataString .= "{x: $ timeInMillis, y: $ cumSum}, " ;
134
135
$ dataSeriesString .= '{x: ' . $ timeInMillis . ', y: ' . $ currentInverterVal . '}, ' ;
135
136
if (!isset ($ totalsumCumArray [$ timeInMillis ])) {
136
137
$ totalsumCumArray [$ timeInMillis ] = 0 ;
@@ -310,7 +311,8 @@ function buildSubtitle(ctx) {
310
311
let dataZonPHP = data.dataZonPHP;
311
312
let txt = data.txt;
312
313
let totalValue = 0;
313
- let lastDate = Date.now();
314
+ let lastDate = new Date();
315
+ lastDate = `${lastDate.getHours()}:${lastDate.getMinutes()}`;
314
316
let lastValue = 0;
315
317
let todayMax = 0;
316
318
let maxDay = Date.now();
@@ -359,9 +361,8 @@ function customDayLegendClick(e, legendItem, legend) {
359
361
cumSum = cloneAndResetY(dataset.dataCUM)
360
362
}
361
363
for (let ii in dataset.data) {
362
-
363
364
// cum
364
- if (dataset.dataCUM[ii].y != null) {
365
+ if (dataset.dataCUM[ii] != null && dataset.dataCUM[ii] .y != null) {
365
366
cumSum[ii].y = cumSum[ii].y + dataset.dataCUM[ii].y;
366
367
}
367
368
}
@@ -387,6 +388,7 @@ function customDayLegendClick(e, legendItem, legend) {
387
388
chart.options.plugins.subtitle = {
388
389
text: buildSubtitle(legend),
389
390
display: true,
391
+ padding: {top: 5, left: 0, right: 0, bottom: 3},
390
392
};
391
393
chart.update();
392
394
}
0 commit comments